F
Filamentβ€’15mo ago
ciorici

Form field value set but saved as "null" in database

I have a form (order) where I am saving the company_id, from a select with a relationship "->relationship('company', 'name')". For some reason on create the field is saved as null in the database even if it's set as required. I tried to check if the data is passed through in the mutateFormDataBeforeCreate function, everything is fine but it still goes empty in the database. The interesting thing is that it is being saved normally after I edit the record, select it again and then save. Any ideas what this could be?
21 Replies
Dan Harrin
Dan Harrinβ€’15mo ago
is it $fillable
ciorici
cioriciβ€’15mo ago
yes, it is. Tried it with the protected $guarded = []; and still no luck
Dan Harrin
Dan Harrinβ€’15mo ago
what is the name of the select
ciorici
cioriciβ€’15mo ago
Dan Harrin
Dan Harrinβ€’15mo ago
i dont know, very weird try and reproduce the problem in a new project and you'll find out where you went wrong
ciorici
cioriciβ€’15mo ago
the most interesting thing is that it happens both on the local server and the production one.
Dennis Koch
Dennis Kochβ€’15mo ago
company is a BelongsTo relation?
ciorici
cioriciβ€’15mo ago
yes
Dennis Koch
Dennis Kochβ€’15mo ago
The filament version is up-to-date? Btw. can we please see the full field definition?
ciorici
cioriciβ€’15mo ago
What do you mean? There is a screenshot above. The only part that is not visible is setting up another field value based on this one afterStateUpdated
Dennis Koch
Dennis Kochβ€’15mo ago
Okay. Just wanted to make sure there isn't anything missing.
ciorici
cioriciβ€’15mo ago
tried to check if the company_id is set here, everything is fine and the right value is set
Dennis Koch
Dennis Kochβ€’15mo ago
What if you manually do Order::create([your_data]) does it save the Order correctly?
ciorici
cioriciβ€’15mo ago
Dennis Koch
Dennis Kochβ€’15mo ago
The Filament stuff looks fine. Anything on your model that could manipulate the data? Can you share your model? Does creating the model directly work?
ciorici
cioriciβ€’15mo ago
This is the model.
Dennis Koch
Dennis Kochβ€’15mo ago
Don't think it should interfere but can you remove the static::creating() hook?
ciorici
cioriciβ€’15mo ago
tried that as I also thought it could be the problem, but doesn't make any difference
Dennis Koch
Dennis Kochβ€’15mo ago
What about this πŸ‘†πŸΌ
ciorici
cioriciβ€’15mo ago
I'm going to try now seems to work fine
Dennis Koch
Dennis Kochβ€’15mo ago
Hm weird. I'm out of ideas. I'd use Xdebug and step through all the steps to find the issue