laravel-livewire-tables
laravel-livewire-tables copied to clipboard
Sorting relationships on table
Hello,
Thank you for this package.
I do have some issues though.
I have these tables: coffees, roast_types, green_beans.
In the Coffee model I have these relationships:
public function roast_type()
{
return $this->belongsTo(RoastType::class);
}
public function green_bean()
{
return $this->belongsTo(GreenBean::class);
}
In the CoffeeTable component I have this query:
return Coffee::with('roast_type')
->with('green_bean')
->where('coffees.active', $this->active)
->where('blend', 0);
and these columns:
return [
Column::make('ID')->searchable()->sortable(),
Column::make('Name')->searchable()->sortable(),
Column::make('Green Bean', 'green_bean.name')->searchable()->sortable(),
Column::make('Roast Type', 'roast_type.name')->searchable()->sortable(),
Column::make()->view('admin.coffee.table_actions'),
];
I have 2 problems:
-
When I click on sorting the Roast Type column the values in the Name column change to the Roast type name instead of the Coffee name.
-
When I click on sorting the Green Bean column, I get this error:
Missing required parameter for [Route: coffees.edit] [URI: coffees/{coffee}/edit] [Missing parameter: coffee]. (View: C:\wamp64\www\highland8.local\resources\views\admin\coffee\table_actions.blade.php)
What am I doing wrong?
BTW, I added some functionality like in the jquery dropdown tables, to show:
- A dropdown for the user to select how many records to display on the page
- A paragraph that shows how many records are displayed from the total results
Can you please help with my issues?
Did you ever get sorting worting for a relationship, I'm facing the same thing and my table is just turning up empty whenever I sort by a relationship?
Hi @gbrits, Yes I did, I don't remember exactly how.
I think I created my own datatable classes and view where I do the db queries myself.
I can send you the files if you want.