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
SQLSTATE[HY000]: General error: 1364 Field 'myField' doesn't have a default value
SQLSTATE[HY000]: General error: 1364 Field 'myField' doesn't have a default value
. How can I save into this field on creation? Thank you.
3 Replies
Sjoerd24
Sjoerd247mo ago
II think a observer and then placing this in the creating() section would very best..?
Abdellah
AbdellahOP7mo ago
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.
Sjoerd24
Sjoerd247mo ago
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.
Want results from more Discord servers?
Add your server