F
Filamentβ€’14mo ago
Bagus A

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?
// how to make select without a table row
Forms\Components\Select::make('category_id')
->relationship(name: 'category', titleAttribute: 'name')
->columnSpanFull()
->required(),
// how to make select without a table row
Forms\Components\Select::make('category_id')
->relationship(name: 'category', titleAttribute: 'name')
->columnSpanFull()
->required(),
7 Replies
Bagus A
Bagus AOPβ€’14mo ago
It's not for table @Vp , but for form.
No description
Bagus A
Bagus AOPβ€’14mo ago
Here I want to add a dropdown for Category Status which contains purchased or not-purchased which is in it's own table row.
Vp
Vpβ€’14mo ago
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.. πŸ˜†
Bagus A
Bagus AOPβ€’14mo ago
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.
Vp
Vpβ€’14mo ago
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 works
Bagus A
Bagus AOPβ€’14mo ago
Your answer gave me the hints. Thank you @Vp
Want results from more Discord servers?
Add your server