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
is it $fillable
yes, it is. Tried it with the protected $guarded = []; and still no luck
what is the name of the select
i dont know, very weird
try and reproduce the problem in a new project and you'll find out where you went wrong
the most interesting thing is that it happens both on the local server and the production one.
company
is a BelongsTo relation?yes
The filament version is up-to-date?
Btw. can we please see the full field definition?
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
Okay. Just wanted to make sure there isn't anything missing.
tried to check if the company_id is set here, everything is fine and the right value is set
What if you manually do
Order::create([your_data])
does it save the Order correctly?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?
This is the model.
Don't think it should interfere but can you remove the
static::creating()
hook?tried that as I also thought it could be the problem, but doesn't make any difference
What about this ππΌ
I'm going to try now
seems to work fine
Hm weird. I'm out of ideas. I'd use Xdebug and step through all the steps to find the issue