public function editRoleAction() { return Tables\Actions\EditAction::make() ->mutateRecordDataUsing(function ($record, $data) { $data['organisation_roles'] = $record->pivot->roles->pluck('id')->toArray(); return $data; }) ->modalWidth(MaxWidth::Large) ->using(function ($record, array $data) { $roles = collect($data['organisation_roles'])->map(function ($role) { return Role::where('id', $role)->firstOrFail()->name; })->toArray(); $record->pivot->syncRoles($roles); $record->update($data); return $record; }) ->form([ Select::make("organisation_roles") ->required() ->options( // Only get roles starting with 'psi' Role::where('name', 'like', 'psi_%') ->pluck('name', 'id') ->mapWithKeys(fn($item, $key) => [$key => __('roles.' . $item)]) ->toArray() ) ->label(__("labels.roles")) ->multiple() ->preload() ]); }
Tables\Columns\TextColumn::make("pivot.roles")
pivot.roles.name