Closed technilogics closed 2 years ago
I used selectable to allow users selection, but some users status is inactive, how i can show only Active user in selectable.
`namespace App\Admin\Selectable;
use App\Models\User; use App\Models\UserType; use Encore\Admin\Grid\Filter; use Encore\Admin\Grid\Selectable;
class Users extends Selectable { public $model = User::class;
public function make() { $this->column('id'); $this->column('name'); $this->column('user_type_id','User Type')->display(function($id) { return ($id ? UserType::find($id)->title_en : null); }); $this->column('email'); $this->column('avatar','Avatar')->image(); $this->column('created_at'); $this->filter(function (Filter $filter) { $filter->like('name'); $filter->equal('user_type_id')->select(UserType::where('status',1)->pluck('title_en', 'id')); }); }
} ` i tried as changing
public $model = User::class;
to
public $model = User::where('status',1);
but it failed, as in grid/selectable
protected function initGrid() method
$model = new $this->model(); $this->grid = new Grid(new $model());
is conflicting with my change.
Any help is appreciated, without changing core admin files.
idk your table, idk I'm right. If it's the same usage as the grid, this should work. $this->model()->where('status', 1);
$this->model()->where('status', 1);
Thanks, this works in make() method $this->model()->where('status', 1);
Description:
I used selectable to allow users selection, but some users status is inactive, how i can show only Active user in selectable.
`namespace App\Admin\Selectable;
use App\Models\User; use App\Models\UserType; use Encore\Admin\Grid\Filter; use Encore\Admin\Grid\Selectable;
class Users extends Selectable { public $model = User::class;
} ` i tried as changing
public $model = User::class;
to
public $model = User::where('status',1);
but it failed, as in grid/selectable
protected function initGrid() method
$model = new $this->model(); $this->grid = new Grid(new $model());
is conflicting with my change.
Any help is appreciated, without changing core admin files.