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?10 Replies
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.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.
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
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())
)
.
.
.
Sorry, but that code is formatted really bad and hard to read π
what about screenshot? π
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
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?
here.
$field is not available.
i don't have any problem to get filters. i have problem to get filterdetails
Solution
problem solved π thanks for your time