Closed rodrigocardenas closed 3 years ago
Any Solution?
I've do this:
Column::callback(['id'], function ($id) {
return MyModel::find($id)->my_attribute;
})->label(__('MyName')),
For now, you should define accesors through callbacks. Seems this package use fluent queries in its inner workings, not Eloquent (that's why model accessors doesn't work).
Hi @carlituxman s solution is not good for huge data in table.
@marksalmon do you have another solution or trick about that ?
Livewire Datatables uses query builder and SQL directly because hydrating eloquent models is not permormant with large datasets. Therefore you do have to redefine your accessors either in an SQL query using Column::raw()
or in a callback method.
@marksalmon the callback should have access to the current row. like
Column::callback(function($row){
return $row->custom_attribute;
})
What's wrong implemting this?
Remember we are always doing:
ModelClass::query()
in the builder method.
So it does not make sense not be able to access computed attributes.
Hi, any way how to use attributes/appends from models? btw nice work thx!