F
Filament11mo ago
Sydd

Select mofiyQueryUsing return only Id on relationship

Dear all, according code under, is modified query but returned to options ID, not name ..., and is possible to show searchable only if option is more than 6 ? Select::make('safirsBranch_id') ->label(('app.safirs.safirsBranch')) ->relationship('safirsBranch', 'safirsBranchName', fn (Builder $query) => $query->where('id', auth()->user()->safirsBranches->pluck('id')->toArray())) ->required() ->native(false) //->searchable() if count of options is more than 6 ->searchable() ->preload() ->placeholder(('app.safirs.safirsBranch')),
2 Replies
toeknee
toeknee11mo ago
You are telling it to return just the 'id' with the ID....
fn (Builder $query) => $query->where('id', auth()->user()->safirsBranches->pluck('id', 'name')))
fn (Builder $query) => $query->where('id', auth()->user()->safirsBranches->pluck('id', 'name')))
Sydd
SyddOP11mo ago
Your code advice look fine, but doesn't work for me. I solve problem with options() :, but dont understand, that name is first, before id 🙂
Select::make('safirsBranch_id')
->label(__('app.safirs.safirsBranch'))
->options(auth()->user()->safirsBranches->pluck('safirsBranchName', 'id')->toArray())
Select::make('safirsBranch_id')
->label(__('app.safirs.safirsBranch'))
->options(auth()->user()->safirsBranches->pluck('safirsBranchName', 'id')->toArray())

Did you find this page helpful?