F
Filamentβ€’9mo ago
matin rajabi

struggle with select field =_=

i create a Select then for its option i have a model which has this relation:
public function filter(): BelongsTo { return $this->belongsTo(Filter::class, 'filters_id'); }
and in Filter::class i have another relation:
public function subfilters(): HasMany { return $this->hasMany(FilterDetail::class); }
and i want that the options will be FilterDetail::class rows what should i do?
Solution:
problem solved πŸ™‚ thanks for your time
Jump to solution
10 Replies
Dennis Koch
Dennis Kochβ€’9mo ago
Use two Selects. First Select selects the filter. Second select is visible as soon as filter is set and shows the subfilters. Check the example in the docs.
matin rajabi
matin rajabiOPβ€’9mo ago
you mean i create dependent select? there is no way to directly access the second relation values? i do have filters there is no selection of filters. the user has no choice, filters are dependent on selected categories so for each existing filter i must create a select and display filter details as its option.
Dennis Koch
Dennis Kochβ€’9mo ago
Oh, yes that should be possible. I thought because they were names "subfilters" that you want to select a filter first That would be a Select with multiple and a relationship
matin rajabi
matin rajabiOPβ€’9mo ago
yes and the problem is id of filter is not accessible in function that i have in ->options scope:
foreach (CategoryFilter::where('category_id', $get('category_id'))->with('filter')->get() as $field) { // dd($field['filter']); $dynamicSchema[] = Select::make($field['filter']['id']); $var=$field['filter']['id'] ->options( function (Get $get, $var=$field['filter']['id']) { // dd($var); return FilterDetail::where('filter_id', $var['filter']['id']) ->get()->pluck('name', 'id'); } // (fn (RelationManager $livewire) => // FilterDetail::where('filter_id', $livewire->ownerRecord->id)->pluck('name', 'id')->toArray()) ) . . .
Dennis Koch
Dennis Kochβ€’9mo ago
Sorry, but that code is formatted really bad and hard to read πŸ˜…
matin rajabi
matin rajabiOPβ€’9mo ago
what about screenshot? πŸ™‚
No description
Dennis Koch
Dennis Kochβ€’9mo ago
That foreach loop doesn't make any sense. $get isn't available there. If you want a select for every category you would need to generate them all an show/hide them using ->hidden()/->visible(). There you can use $get
matin rajabi
matin rajabiOPβ€’9mo ago
look i already have the categories i can't get the filterdetails. where is filterdetails? this is the path: with category_id -> get the filter_id and with this -> get the filterdetails of each filter_id.
my problem is that i can not access the filter_id in ->options i just want to know is there any way that i can get my filter id in options scope?
matin rajabi
matin rajabiOPβ€’9mo ago
here. $field is not available. i don't have any problem to get filters. i have problem to get filterdetails
No description
Solution
matin rajabi
matin rajabiβ€’9mo ago
problem solved πŸ™‚ thanks for your time
Want results from more Discord servers?
Add your server