F
Filamentmatin 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
DK
Dennis Kochβ€’44d 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.
MR
matin rajabiβ€’44d 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.
DK
Dennis Kochβ€’44d 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
MR
matin rajabiβ€’44d 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()) ) . . .
DK
Dennis Kochβ€’44d ago
Sorry, but that code is formatted really bad and hard to read πŸ˜…
MR
matin rajabiβ€’44d ago
what about screenshot? πŸ™‚
No description
DK
Dennis Kochβ€’44d 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
MR
matin rajabiβ€’44d 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?
MR
matin rajabiβ€’44d ago
here. $field is not available. i don't have any problem to get filters. i have problem to get filterdetails
No description
Solution
MR
matin rajabiβ€’43d ago
problem solved πŸ™‚ thanks for your time
Want results from more Discord servers?
Add your server
More Posts
what merhod to use in import action: castStateUsing or filstateUsingHi everyone, i have a table with id and name and i want to modify name, while importing, based on a Weird login error after livewire updateAfter `composer update` I can't login to filament. I see the login form but the password field is aReusable sectionsHi, I was wondering how you usually create reusable parts for example e.g. infolists or forms? For efiltersForm()Im using custom livewire page with widget with table. I have defined filter form and $this->filters JS error : "Livewire assets are out of date"Hi guys, I made a few changes on my Filament app and now login isn't working anymore and I think it'It's possible to put the relation on top of form page?I have a big form. After create a record ( with doesn't have the relation fields already ), a user dWork with existing tables without deleting their contents when doing migrationsHi guys, I'd like to work with already existing data in the database. Unfortunately the table is deAction opening an empty state modalI'm using Action in a spatie livewire wizard component. When I click on next button once, the step iBlock Repeater Rating with MorphToMany RelationGreetings, I have a block with this form inside class Rating { public static function make( Ignore using filament:assets for packageI am using this package for inspiration: https://github.com/cheesegrits/filament-google-maps and fouHow to increase Pest test coverageHey, I am attempting to increase my test coverage to 100% for my resources and can't seem to figurHow to put images in a textarea with filament ?I've tried a lot of things but when I insert my images in a textarea, and that I go back to the fronfile uploading to S3 on vapor stuck on uploadingI have set a new server on Laravel Vapor, the S3 was generated by vapor with full public access, theUse filament Components outside filamentCan I use filament components like a table outside filament assuming I have a simple laravel app witDoes --generate flag work when creating a resource?To test it I: 1- Updated filament libs (`composer update`) & cleared cache `php artisan optimize:clMissing New panel resources - links don't appear on sidebar - 404-Not foundHello. I have been developing an app since the beginning of February and everthing was Ok. I have beNested relation formHi guys, is it possible to create form with nested relations? ```php // ClientResource.php Forms\CoDispatching a livewire event from a filament action when submitHello, I need help dispatching a livewire event from a filament action but none of the answers or meButton loading animation too fastIs this button loading animation intentionally designed like this ? i think it is too fastAction afterStateHydratedHello, i want to fire a Action after a user has chosen something in the dropdown of my form, how can