You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
we cant filter belongsToMany records. Multiselect::make('Admins') ->belongsToMany(User::class, false),
I wanted to load only admin users in admins list, but I could not found any way to filter. So I changes my code as below. Multiselect::make('Admins') ->options($users) ->resolveUsing(function ($value) { return $this->resource->admins->pluck('id')->toArray(); }) ->fillUsing(function ($request, $model, $attribute, $requestAttribute) { // Save the community first to obtain its ID $model->save(); $adminIds = $request->input($requestAttribute, []); $admins = []; foreach ($adminIds as $adminId) { $admins[$adminId] = ['is_admin' => true, 'created_at' => now()]; } $model->enroller()->sync($admins); }) ->displayUsing(function ($value) { return $value->pluck('name', 'id')->toArray(); }),
In both the cases, when I do not filter my records and use ->belongsToMany(User::class, false) or when I filter my records by using above mentioned code, update is giving an error
Call to a member function getMorphClass() on null
The text was updated successfully, but these errors were encountered:
Couple of issue:
we cant filter belongsToMany records.
Multiselect::make('Admins') ->belongsToMany(User::class, false),
I wanted to load only admin users in admins list, but I could not found any way to filter. So I changes my code as below.
Multiselect::make('Admins') ->options($users) ->resolveUsing(function ($value) { return $this->resource->admins->pluck('id')->toArray(); }) ->fillUsing(function ($request, $model, $attribute, $requestAttribute) { // Save the community first to obtain its ID $model->save(); $adminIds = $request->input($requestAttribute, []); $admins = []; foreach ($adminIds as $adminId) { $admins[$adminId] = ['is_admin' => true, 'created_at' => now()]; } $model->enroller()->sync($admins); }) ->displayUsing(function ($value) { return $value->pluck('name', 'id')->toArray(); }),
In both the cases, when I do not filter my records and use ->belongsToMany(User::class, false) or when I filter my records by using above mentioned code, update is giving an error
The text was updated successfully, but these errors were encountered: