ward
ward
FFilament
Created by ward on 8/14/2024 in #❓┊help
Filtering select options on-fly
Ok, I found that Select isn't the best option here. If I make this for CheckboxList instead, it can properly re-render available options as my intention was. Don't think that Select is really capable of that without re-opening it.
5 replies
FFilament
Created by ward on 8/14/2024 in #❓┊help
Filtering select options on-fly
Field looks like so:
Select::make('position')
->required()
->multiple()
->preload()
->live()
->options(static function (string $operation, ?array $state) {
if ($operation === 'create' && is_array($state) && count($state)) {
// Since we allow for one ad in multiple positions to have one format,
// we will limit positions based on first picked position dimensions in order
// to not create a bug where certain larger ad is shown in smaller ad spot.
$position = AdvertisementPosition::find(intval($state[0]));

return AdvertisementPosition::query()
->where('width_px', $position->width_px)
->where('height_px', $position->height_px)
->get();
}

return AdvertisementPosition::query()->tap(new ActiveAdvertisement);
})
->relationship(
name: 'positions',
modifyQueryUsing: static function (Builder $query, string $operation) {
return $operation === 'create'
? $query->tap(new AvailableAdPosition)
: $query;
}
)
Select::make('position')
->required()
->multiple()
->preload()
->live()
->options(static function (string $operation, ?array $state) {
if ($operation === 'create' && is_array($state) && count($state)) {
// Since we allow for one ad in multiple positions to have one format,
// we will limit positions based on first picked position dimensions in order
// to not create a bug where certain larger ad is shown in smaller ad spot.
$position = AdvertisementPosition::find(intval($state[0]));

return AdvertisementPosition::query()
->where('width_px', $position->width_px)
->where('height_px', $position->height_px)
->get();
}

return AdvertisementPosition::query()->tap(new ActiveAdvertisement);
})
->relationship(
name: 'positions',
modifyQueryUsing: static function (Builder $query, string $operation) {
return $operation === 'create'
? $query->tap(new AvailableAdPosition)
: $query;
}
)
Putting what I have in options does not change anything.
5 replies
FFilament
Created by Oddman on 11/9/2023 in #❓┊help
Repeater relationship failing as it returns null
I need a fresh link
6 replies
FFilament
Created by qcol on 9/4/2023 in #❓┊help
Nested resource
https://laraveldaily.com/post/filament-nested-resources-courses-lessons This seem to fit your situation. As I've been researching, there seems to be no easy way of handling it. Vastly easier to just overwrite queries that lead to records getting created.
7 replies