Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update issue with belongsToMany #221

Open
x2princ3 opened this issue Jun 15, 2023 · 1 comment
Open

Update issue with belongsToMany #221

x2princ3 opened this issue Jun 15, 2023 · 1 comment
Labels
needs input Waiting for the reporter to reply.

Comments

@x2princ3
Copy link

Couple of issue:

  1. 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(); }),

  2. 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

@Tarpsvo
Copy link
Collaborator

Tarpsvo commented Jun 30, 2023

Can you provide me with more information, like a stack trace of where the getMorphClass error occurs? Thanks.

@Tarpsvo Tarpsvo added the needs input Waiting for the reporter to reply. label Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs input Waiting for the reporter to reply.
Projects
None yet
Development

No branches or pull requests

2 participants