Save a field when creating a model
Hello, I have a
casts
field in my model and I want to save two other fields into the particular field.
This question is similar https://discord.com/channels/883083792112300104/1081223982960885771 but the provided solution does not work for me while using mutateFormDataBeforeCreate
The field I want I can set it inside mutateFormDataBeforeCreate
but it fails .
How can I save into this field on creation?
Thank you.3 Replies
II think a observer and then placing this in the creating() section would very best..?
Hey @Sjoerd24, thank you for the input. Please can you elaborate on the observer case? I am a little new to Laravel after doing exclusively Symfony for like 4 years.
https://laravel.com/docs/11.x/eloquent there is almost everything you need to know. You add in your model sth like Observedby, works super easy. I use it for so many things, such as perfect solution for 70% of my problems. 😎
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.