How to use form fields that doesn't save to a table
Let's say I have 2 tables
Category => name, status (available options 'purchased' or 'not-purchased')
Part => name, category_id
How do I add a new field to filter category dropdown based on status for PartResource?
7 Replies
It's not for table @Vp , but for form.
Here I want to add a dropdown for Category Status which contains purchased or not-purchased which is in it's own table row.
I am not really sure then, but create/update "category" status from PartResource is a little strange.. But this may work:
1. create select with options ('purchase', 'notpurchase')
2. Update the categories_table using
afterCreate()
https://filamentphp.com/docs/3.x/panels/resources/creating-records#lifecycle-hooks
3. You can exclude the status from mutateFormDataBeforeCreate()
https://filamentphp.com/docs/3.x/panels/resources/creating-records#customizing-data-before-saving
But like I said, may work.. πI'm not creating or updating "category" from Part. But, I want to filter Category by it's status. So something like dependant dropdown, but not from other resource.
Since I need to filter Category first based on it's status, I'm not sure which Component feature I could use.
Oh... totally missed the key points.. sorry
Wait a few second, this can be done easily tho
1. You can create select with options (status) like
Select::make('status_select')->options(['a','b'])
2. Put ->live()
to status_select
3. Filter your category select relation data using $get('status_select')
https://filamentphp.com/docs/3.x/forms/fields/select#customizing-the-relationship-query
Hope this worksYour answer gave me the hints. Thank you @Vp