21 Replies
The purpose of this is to set the selected value in a select from a relation, is there another way to manage the create and edit without the isset condition?
->afterStateHydrated(static function ($component, $state) use ($product_id) {
$selected = array_intersect($product_id, $state);
$component->state(array_keys($selected));
}),
Maybe this will work im not sure
If your model have relation, you probably can remove the afterStateHydrate
And use Select::make(‘product.year_id’)
Are you sure this works? For me it's not displaying anything.
then your relationship isn't working
Doing the Select from the relationship should return the year_id if you have year_id on your product relationship.
Table : years
- id
- year
Table : products
- id
- name
- description
- year_id
Table : region
- id
- name
- description
- product_id
Model : year
Model : product
Model : region
What I need is to display and set selected field for edit.
Select::make('year_id')->relationship('year', 'year') ?
Yes it's working only for second model, sorry forgot to add the third one.
What’s the third? We need more detail. It doesn’t matter how many relationships you have, providing they work you can harness them with the dot syntax
Are you trying to do this?
I'm trying to avoid using ->afterStateHydrated,
using the chained relations in Region ressource.
I'm trying to figure out what's wrong from the Region ressource,
This works because I'm just getting the value year from the table years?
This don't because I'm trying to get all the year values from the table years?
So the problem is my relation right?
I'm learning this relations thing, but i feel kinda lost right now 😦
Did you try this?
Yes! It's working, thank you, will it work with more dependant selects?
Should work
You may use Group instead of Card if you want, I think
Sorry but I can't find Group in the docs?
Surprised it’s not in the docs but it exists as a layout component. https://github.com/filamentphp/filament/blob/2.x/packages/forms/src/Components/Group.php
GitHub
filament/Group.php at 2.x · filamentphp/filament
Admin panel, form builder and table builder for Laravel. Built with the TALL stack. Designed for humans. - filament/Group.php at 2.x · filamentphp/filament
Thank you 🙂
I don’t see any indication that it’s deprecated either. Weird is not in the docs.
I use it all the time.
The problem I have with Group is that one group only resizes to half of the page, I have create two groups to fill the page.
How can I access the select value "year_id" after the two relationships?
Livewire returns it inside an array "product".
Access it where? In the form it should just be dot notation ‘product.year_id’. In your component it’s just a php array.
Thanks it's working!