laravel-livewire-tables
laravel-livewire-tables copied to clipboard
Example for restricting the results
It has taken me more time than it should... I only wanted users with the role_id = 1
I now have a solution and I wanted to share it.
class UserTable extends TableComponent { public $role_id; public function query() { if ($this->role_id!= null) return User::where('role_id',$this->role_id); return User::query(); } public function mount($role_id= null) { $this->setTableProperties(); if ($role_id!= null) $this->role_id= $role_id; } public function columns() { return [ Column::make('ID')->searchable()->sortable(), Column::make('url')->searchable()->sortable(), Column::make('status')->searchable()->sortable(), Column::make('type')->searchable()->sortable(), Column::make('role')->searchable()->sortable(), Column::make('processed_at')->searchable()->sortable(), Column::make('Created At')->searchable()->sortable(), Column::make('Updated At')->searchable()->sortable(), ]; } }
and in the view:
@livewire('user-table',['role_id'=>$role->id])
I hope I could help