skip to Main Content

Heyya,

I am working on Select

FormsComponentsSelect::make('roles')->options(function (){
                            $roles = Role::pluck('name');
                            $filtered_roles = $roles->filter(fn($role)=>$role!='super_admin');
                            return $filtered_roles;
                        })->searchable()->preload()->multiple()

Works great. However on the edit page it doesnt show already defined roles for specific user. Each time it show select one of the roles

I expect it would show me currently selected roles on edit

2

Answers


  1. Chosen as BEST ANSWER

    Okay here is a solution i manage to find myself.

    FormsComponentsSelect::make('roles')
                                ->relationship('roles', 'name', fn(Builder $query) => $query->whereNot('name', 'super_admin'))
                                ->searchable()
                                ->preload()
                                ->multiple()
    

    I hope it will be useful for you guys who suffer same situation.


  2. Use fill() in mount()

    function mount()
    {
      $this->form->fill([
        'roles' => $user->roles->pluck('name')
      ]);
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search