Toggle without mass assignement
Hi guys,
I want to add toggle to my UserResource and use value from it in afterCreate hook to generate and send password via email. But I dont want to have this value from toggle saved on model.
How can I prevent this error:
Add fillable property [send_credentials] to allow mass assignment on [App\Models\User].
and access that property on afterCreate hook?8 Replies
->dehydrated(false)
in Toggle
read more https://filamentphp.com/docs/3.x/forms/advanced#preventing-a-field-from-being-dehydratedThank you. Can you help me with second part of this issue? I want to generate random password. It should be generated probably in beforeCreate, but mail should be send in afterCreate.
Or should I send that email also in beforeCreate?
Wait, my answer will be incorrect.. I don't think you can access
send_credentials
in ->afterCreate()
if you don't save in DB.Can I access it in beforeCreate?
Can you try out first.. I am not sure both 🤣
For password, you can store in variable, and use in both create and after create..
In constructor?
No, something like this
I did it like this:
I have a hunch that there is a better solution, but I haven't figured it out.