laravel-livewire-tables
laravel-livewire-tables copied to clipboard
[Bug]: Undefined property: stdClass::$id when using select all checkbox
What happened?
When clicking on the checkbox an error occurs
After investigating i came across this: In this function
I noticed this function doesnt include the selects used in the columns method.
When using dd
in the elequent method the response is:
It misses all the columns i added in the columns
section.
How to reproduce the bug
No response
Package Version
latest
PHP Version
8.2.x
Laravel Version
10
Alpine Version
latest
Theme
Tailwind 3.x
Notes
No response
Error Message
Undefined property: stdClass::$id
Make sure that you either have a column for the "id" field, or that it is added via setAdditionalSelects in your configure() method
Make sure that you either have a column for the "id" field, or that it is added via setAdditionalSelects in your configure() method
I have the column set as primary key and i show it in the table.
Same issue here. Also have an ID column visible on the table itself... so no need to setAdditionalSelects
.
This happens when I do $this->setAllSelected()
Update: I was able to resolve it by manually adding id
to the query:
public function builder(): Builder
{
return MyModel::query()->select(['id', 'col', ...]);
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
You don't need to add the fields to the setAdditionalSelects so long as it's not a label() Column, if it is, then by design it doesn't add it inro the query.
Adding a select() method in your builder method may result in oddities, as it builds the query and selects the relevant fields internally.