can't assign role to customer
i was trying to assign when customer is created i created a user for the customer in aftercreate method then assign customer role but am getting this error and here is my code resource
i think the relationship is causing the error any idea plz
8 Replies
@Adnan Yalahow You didn't post the code from your
afterCreate()
so it's hard to say. But the error points at the fact that USER is not passed correctly to the ->assignRole()
method of Spatie packagehere is my aftercreate function the reason i did not post is because its not reached
i cant even see ""Am here""
So where is that screenshot error comes from if your
assignRole()
code isn't even called?am thinking this part of the form is causing the error that relationship line
and this is my customer model
In this code, I don't see anything that would automatically save any roles to "model_has_roles" table. That DB table comes from the package, and from what I remember it's called only in methods like
->assignRole()
which I don't see in your latest code. Sorry, I guess it's not solvable on Discord without real debugging and putting dd() everywhere until you find where the error comes from 🙂i have been really trying hard on this. But would you suggest anything from your experience, I am trying to create a customer and i want to give a role as i create that customer and after i will use that for the customer to view his own data i really appriciate you assistance
Not sure if this is applicable in your situation but maybe this tutorial would help? https://laraveldaily.com/post/filament-register-auto-assign-role-spatie-permission
Thank you i will check out