Filling default value in forms via relationship
So lets say I have Categories that have a single Menu. Is there a way to create a dummy record with
menu_id
pre-defined, so when I am creating it would just fetch based on a defined menu_id
and fill a title
from the Menu
In a regular Laravel I could just:
How would it be possible to achieve a similar logic in a filament? Thanks.13 Replies
Unknown Userβ’2y ago
Message Not Public
Sign In & Join Server To View
I think you are looking for this
https://filamentphp.com/docs/2.x/admin/resources/creating-records#customizing-the-creation-process
Filament
Creating records - Resources - Admin Panel - Filament
The elegant TALL stack admin panel for Laravel artisans.
Thanks. I think it's after user clicks "Create" button and data is about to get inserted into database but I need something where I could offer a dummy model with just menu_id before form is filled in CreatePage
Why do you need the
menu_id
in the form?I want to display disabled value as reference for the user, so he would be well informed for what menu category is getting created. π
Hidden field in my example acts as relation ID and TextInput with dehydrate(true) is for user information.
so I was trying with fillForm now but something is still missing. This is called before form is loaded so I guess it's right spot to override.
form->fill pass menu_id in my example. I have looked at how EditPage does it.
hidden field gets populated though π
so this place receives data through fill but relationship is somehow not triggered
Ah, you tried to prefill the relation by setting a menu_id field. That doesn't work. Not sure what's the best approach to prefill Layout relationships
This is not getting triggered on a create page load but not found what prevents it yet. :/
Probably because there is usually no state on create
You could try adding data inside
mount()
yeh, I was following the hydrateState on the components right now and that's where it gets skipped
yeh so basically it gets cut off here because my dummy model is market as non existant