laravel-livewire-tables icon indicating copy to clipboard operation
laravel-livewire-tables copied to clipboard

Example for restricting the results

Open merlinro opened this issue 5 years ago • 0 comments

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

merlinro avatar Nov 10 '20 20:11 merlinro