F
Filament13mo ago
Sidem

default select on relationship

Hello, i would like put a default value for my filter select but that didn"t works :
SelectFilter::make('exercice')
->label('Exercice')
->relationship('exercice', 'name', fn($query) => $query->orderBy('id', 'desc') )
->default(2022)
->searchable()
->multiple()
->preload(),
SelectFilter::make('exercice')
->label('Exercice')
->relationship('exercice', 'name', fn($query) => $query->orderBy('id', 'desc') )
->default(2022)
->searchable()
->multiple()
->preload(),
The table Exercice looks like :
No description
Solution:
It is multiple, try: ->default([1])...
Jump to solution
4 Replies
ConnorHowell
ConnorHowell13mo ago
The default would need to be the primary key of the default value. So in this case if you put 1 as the default it would show 2022
Sidem
SidemOP13mo ago
I already try this but its didn't works :
SelectFilter::make('exercice')
->label('Exercice')
->relationship('exercice', 'name', fn($query) => $query->orderBy('id', 'desc') )
->default(1)
->searchable()
->multiple()
->preload(),
SelectFilter::make('exercice')
->label('Exercice')
->relationship('exercice', 'name', fn($query) => $query->orderBy('id', 'desc') )
->default(1)
->searchable()
->multiple()
->preload(),
no filter is put on default with this code
Solution
toeknee
toeknee13mo ago
It is multiple, try: ->default([1])
Sidem
SidemOP13mo ago
Its works ! Thanks a lot !
Want results from more Discord servers?
Add your server