F
Filament8mo 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
ConnorHowell8mo 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
Sidem8mo 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
toeknee8mo ago
It is multiple, try: ->default([1])
Sidem
Sidem8mo ago
Its works ! Thanks a lot !