MedicOneSystems / MedicOneSystems/livewire-datatables
Making multiple callbacks using the same column
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 1.2k
- Forks
- 257
- PR merge metrics
- No merged PRs in 30d
Description
I need to make two callbacks using the data from the id column but every time I use the second callback, I get an error saying duplication column name, so I decided to use it this way:
## Rule Source column
Column::callback(['id'], function ($abc) {
$arr['szone'] = PolicyRuleSrcZone::where('id',$abc)->get();
$arr['saddr'] = PolicyRuleSrcIP::where('id',$abc)->get();
return view('livewire.policies.rules.table-source',['value'=>$arr]);
})->label('Source'),
Column::callback(['id','category.name'], function ($a,$b) { <<<<<
$arr['dzone'] = PolicyRuleDstZone::where('id',1)->get();
$arr['daddr'] = PolicyRuleDstIP::where('id',1)->get();
#return 1;
return view('livewire.policies.rules.table-destination',['value'=>$arr]);
})->label('Destination'),
I am trying to use the value of the relationship policy_rule->category->name (in bold) but it keeps showing an error as below
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax
Am I using it incorrectly in the callback ? by the way, it works with no issues if I used the same as below in anything but a callback
Column::name('category.name')
# ->label('ID')
# ->sortBy('id'),
Is there a way or specific format that I should use to get or access the value of a relationship
Thanks.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the callback definitions and the Column::name('category.name') usage shown in the issue, then trace how callback columns build their query arguments. Reproduce the duplicate-column and SQL syntax errors with the two callbacks. Done means both callbacks can use id and the category.name relationship without generating invalid SQL.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- laravel, php
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100