F
Filamentβ€’2y 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β€’2y ago
is it $fillable
ciorici
cioriciOPβ€’2y ago
yes, it is. Tried it with the protected $guarded = []; and still no luck
Dan Harrin
Dan Harrinβ€’2y ago
what is the name of the select
ciorici
cioriciOPβ€’2y ago
Dan Harrin
Dan Harrinβ€’2y 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
cioriciOPβ€’2y ago
the most interesting thing is that it happens both on the local server and the production one.
Dennis Koch
Dennis Kochβ€’2y ago
company is a BelongsTo relation?
ciorici
cioriciOPβ€’2y ago
yes
Dennis Koch
Dennis Kochβ€’2y ago
The filament version is up-to-date? Btw. can we please see the full field definition?
ciorici
cioriciOPβ€’2y 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β€’2y ago
Okay. Just wanted to make sure there isn't anything missing.
ciorici
cioriciOPβ€’2y ago
tried to check if the company_id is set here, everything is fine and the right value is set
Dennis Koch
Dennis Kochβ€’2y ago
What if you manually do Order::create([your_data]) does it save the Order correctly?
ciorici
cioriciOPβ€’2y ago
Dennis Koch
Dennis Kochβ€’2y 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
cioriciOPβ€’2y ago
This is the model.
Dennis Koch
Dennis Kochβ€’2y ago
Don't think it should interfere but can you remove the static::creating() hook?
ciorici
cioriciOPβ€’2y ago
tried that as I also thought it could be the problem, but doesn't make any difference
Dennis Koch
Dennis Kochβ€’2y ago
What about this πŸ‘†πŸΌ
ciorici
cioriciOPβ€’2y ago
I'm going to try now seems to work fine
Dennis Koch
Dennis Kochβ€’2y ago
Hm weird. I'm out of ideas. I'd use Xdebug and step through all the steps to find the issue
Want results from more Discord servers?
Add your server