F
Filamentβ€’12mo ago
Jordy

Default value for a table filter with a morpTo select

where does one put the ->default() on something like this:
Filter::make('assigned')
->form([
MorphToSelect::make('assigned')
->model(ChecklistItem::class)
->types([
Type::make(User::class)
->titleColumnName('name'),
Type::make(Team::class)
->titleColumnName('name')
])->searchable(),
])
->query(function (Builder $query, array $data): Builder {
if (!$data['assigned_type'] || !$data['assigned_id']) {
return $query;
}

return $query->where('assigned_type', $data['assigned_type'])->where('assigned_id', $data['assigned_id']);
});
Filter::make('assigned')
->form([
MorphToSelect::make('assigned')
->model(ChecklistItem::class)
->types([
Type::make(User::class)
->titleColumnName('name'),
Type::make(Team::class)
->titleColumnName('name')
])->searchable(),
])
->query(function (Builder $query, array $data): Builder {
if (!$data['assigned_type'] || !$data['assigned_id']) {
return $query;
}

return $query->where('assigned_type', $data['assigned_type'])->where('assigned_id', $data['assigned_id']);
});
Solution:
You would put it on the MorphToSelect I suspect returning an array?
Jump to solution
13 Replies
Jordy
JordyOPβ€’12mo ago
one day discord will propperly format.. I want to filter to assigned to auth user, but how to set said value to the MorpToSelect as it has two values I dont really see how to do it with the ->default() method I had it working without the MorphToSelect as I would just default both selects, I am sure there is a clever way to do this as behind the scenes it should just be two selects
Solution
toeknee
toekneeβ€’12mo ago
You would put it on the MorphToSelect I suspect returning an array?
Jordy
JordyOPβ€’12mo ago
was thinking the same but
->default([
'assigned_type' => User::class,
'assigned_id' => auth()->user()->id,
])
->default([
'assigned_type' => User::class,
'assigned_id' => auth()->user()->id,
])
does nothing not on the filter nor on the MorphToSelect tried without defining the type/id but doesnt work either.. and alot of other things tbh but cant get it to work sadly.. was hoping I was beeing silly
Dan Harrin
Dan Harrinβ€’12mo ago
sounds like a bug as thats where you should put it probably
Jordy
JordyOPβ€’12mo ago
want me to try to make a reproduction repo or?
Dan Harrin
Dan Harrinβ€’12mo ago
pls
Jordy
JordyOPβ€’12mo ago
alr, will let you know when i got it.. need to run to school in a bit sadge
Dan Harrin
Dan Harrinβ€’12mo ago
youngster
Jordy
JordyOPβ€’12mo ago
πŸ˜‚ ffs seems to work in v3 peepoStare check tomorrow if its something else in our project causing it then
Dan Harrin
Dan Harrinβ€’12mo ago
oh you're on v2?
Jordy
JordyOPβ€’12mo ago
yeah cant reproduce so must be something with my morph then, will dig in later. ...apperently when you sleep on it for a night it just magically works the next morning.. I changed absolutely nothing except throwing the container up πŸ’€ well, thanks for the help haha
toeknee
toekneeβ€’12mo ago
sounds like caching πŸ˜›
Jordy
JordyOPβ€’12mo ago
nah, not in dev.. didnt persist in session either :P
Want results from more Discord servers?
Add your server