Benjamin
Benjamin
FFilament
Created by Benjamin on 1/20/2025 in #❓┊help
Performance issue with BulkAction : selectedRecords (only IDs, not Eloquent?)
I'll try it next week and give you a feedback, thanks !
11 replies
FFilament
Created by Benjamin on 1/20/2025 in #❓┊help
Performance issue with BulkAction : selectedRecords (only IDs, not Eloquent?)
It's working but not sure this is optimal. I added this method in my ListMissions page :
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
ExportAction::make()->exports([
MissionExport::make()
->modifyQueryUsing(fn (HasTable $livewire) => $livewire->getFilteredTableQuery()
->with([
'collaborator',
'coordinator',
'days',
'group',
'groupLabel',
'institution.canton',
'latestConfirmation',
'proposals',
'trainingLevels',
])
->withCount(['proposals', 'workedDays'])
->toBase()
->orderBy('missions.id', 'desc')),
]),
// Actions\Action::make('export-test')
// ->action(fn () => dump($this->getFilteredTableQuery()->count())),
// Actions\ActionGroup::make([
// MissionHoursCheckExportAction::action(),
// ])
// ->label('Exports')
// ->icon('heroicon-m-arrow-up-on-square')
// ->outlined()
// ->color('info')
// ->button(),
];
}
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
ExportAction::make()->exports([
MissionExport::make()
->modifyQueryUsing(fn (HasTable $livewire) => $livewire->getFilteredTableQuery()
->with([
'collaborator',
'coordinator',
'days',
'group',
'groupLabel',
'institution.canton',
'latestConfirmation',
'proposals',
'trainingLevels',
])
->withCount(['proposals', 'workedDays'])
->toBase()
->orderBy('missions.id', 'desc')),
]),
// Actions\Action::make('export-test')
// ->action(fn () => dump($this->getFilteredTableQuery()->count())),
// Actions\ActionGroup::make([
// MissionHoursCheckExportAction::action(),
// ])
// ->label('Exports')
// ->icon('heroicon-m-arrow-up-on-square')
// ->outlined()
// ->color('info')
// ->button(),
];
}
It works, but I can't move the modifyQueryUsing() inside my MissionExport class because I can't access the livewire component inside the setUp method. Maybe a better solution would be to be able to use a callback on the exports() method of the ExportAction, and override the getQuery() default behavior by passing a custom query, maybe as an optional parameter in the make() method of the ExcelExport class ? What do you think @Dennis Koch ?
11 replies
FFilament
Created by Benjamin on 1/20/2025 in #❓┊help
Performance issue with BulkAction : selectedRecords (only IDs, not Eloquent?)
->headerActions([
Actions\Action::make('export-test')
->action(fn (HasTable $livewire) => dump($table->getFilteredTableQuery()->count())),
])
->headerActions([
Actions\Action::make('export-test')
->action(fn (HasTable $livewire) => dump($table->getFilteredTableQuery()->count())),
])
Okay it works like that, I will try to combine that and your Filament Excel package 🧐
11 replies
FFilament
Created by Benjamin on 1/20/2025 in #❓┊help
Performance issue with BulkAction : selectedRecords (only IDs, not Eloquent?)
The searching/filtering could be enough. I'll try this, thanks !
11 replies
FFilament
Created by Benjamin on 1/20/2025 in #❓┊help
Performance issue with BulkAction : selectedRecords (only IDs, not Eloquent?)
Up ☝️
11 replies
FFilament
Created by Benjamin on 1/20/2025 in #❓┊help
Performance issue with BulkAction : selectedRecords (only IDs, not Eloquent?)
A possibility to fix it without ruling out Eloquent could be to use chunk() ? Maybe it's already the case, idk.
11 replies
FFilament
Created by Benjamin on 11/28/2024 in #❓┊help
Table filters : column not found, why ?
For example here, why the $query is a neutral Builder (same as doing User::query()) and not the same query of the table that is used to fill the table, in $table->query() ? Does it mean that, for each filter, it makes another SQL query and then filter the table by IDs comparison ?
Tables\Filters\Filter::make('hasMinimumAvailabilityScore')
->label('Au moins 10% de disponibilité')
->query(fn (Builder $query): Builder => $query->where('availabilityScore', '10')),
Tables\Filters\Filter::make('hasMinimumAvailabilityScore')
->label('Au moins 10% de disponibilité')
->query(fn (Builder $query): Builder => $query->where('availabilityScore', '10')),
7 replies
FFilament
Created by Benjamin on 11/28/2024 in #❓┊help
Table filters : column not found, why ?
And I don't need to load the availabilityScore each time I get a user, I only need it for this table so I don't want those data to be load each time I load the user model.
7 replies
FFilament
Created by Benjamin on 11/28/2024 in #❓┊help
Table filters : column not found, why ?
No, I make a joinSub() and an addSelect() in the $table->query() method. Accessor could work, I thought about it but was concerned about the performance. With an accessor, it will make one additional query to the availabilities table no ?
7 replies
FFilament
Created by Benjamin on 11/19/2024 in #❓┊help
Why wire:dirty not working with <x-filament::> components ?
The only turn-around I found is this :
<div class="flex justify-center" wire:dirty.class="hidden">
<x-filament::button wire:click="validateTimeslots">
{{ __('Confirm') }}
</x-filament::button>
</div>

<div class="flex justify-center hidden" wire:dirty.class.remove="hidden">
<x-filament::button disabled>
{{ __('Confirm') }}
</x-filament::button>
</div>
<div class="flex justify-center" wire:dirty.class="hidden">
<x-filament::button wire:click="validateTimeslots">
{{ __('Confirm') }}
</x-filament::button>
</div>

<div class="flex justify-center hidden" wire:dirty.class.remove="hidden">
<x-filament::button disabled>
{{ __('Confirm') }}
</x-filament::button>
</div>
3 replies
FFilament
Created by Benjamin on 10/22/2024 in #❓┊help
Struggling with SelectFilter with relationship() and distinct status (Enum)
I foud similar issues (https://github.com/filamentphp/filament/issues/12948 + https://github.com/filamentphp/filament/issues/10086), and I finally used a custom filter :
Tables\Filters\Filter::make('abacus_status')
->indicateUsing(function (array $data): ?string {
if (!$status = $data['abacus_status']) {
return null;
}

$status = $status instanceof AbacusStatusEnum ? $status : AbacusStatusEnum::from($status);

return __('Status') . ' Abacus' . ': ' . $status->getLabel();
})
->form([
Forms\Components\Select::make('abacus_status')
->label(__('Status') . ' Abacus')
->options(AbacusStatusEnum::class),
])
->query(function (Builder $query, array $data): Builder {
if (!$status = $data['abacus_status']) {
return $query;
}

$status = $status instanceof AbacusStatusEnum ? $status : AbacusStatusEnum::from($status);

return $query->whereAbacusStatus($status);
}),
Tables\Filters\Filter::make('abacus_status')
->indicateUsing(function (array $data): ?string {
if (!$status = $data['abacus_status']) {
return null;
}

$status = $status instanceof AbacusStatusEnum ? $status : AbacusStatusEnum::from($status);

return __('Status') . ' Abacus' . ': ' . $status->getLabel();
})
->form([
Forms\Components\Select::make('abacus_status')
->label(__('Status') . ' Abacus')
->options(AbacusStatusEnum::class),
])
->query(function (Builder $query, array $data): Builder {
if (!$status = $data['abacus_status']) {
return $query;
}

$status = $status instanceof AbacusStatusEnum ? $status : AbacusStatusEnum::from($status);

return $query->whereAbacusStatus($status);
}),
3 replies
FFilament
Created by Gavrisimo on 9/18/2024 in #❓┊help
console error with fresh custom widget
Same here, thanks for the indirect help :p
4 replies
FFilament
Created by Benjamin on 9/28/2024 in #❓┊help
validate() vs getState()
Okay, so if I don't want to save some data in my database, I should call getState() and manually remove them from the array, even if the components are ->hidden() ? 🧐 My hope was to just use ->hidden() on some components conditionally to not save them later.
8 replies
FFilament
Created by Benjamin on 9/28/2024 in #❓┊help
validate() vs getState()
Okay thanks! But I see that getSate() is doing some other stuff (dehydrateState, mutateDehydratedState(), etc.), so it that safe to just call $this->form->validate() ? Maybe I need to run them both ?
8 replies
FFilament
Created by @nasilemak on 1/14/2024 in #❓┊help
Does @livewireScripts directive still need to be included when using @filamentScripts?
Oh okay, this code was not working :
@filamentScripts
<!-- @livewireScripts -->
<!-- @livewireScriptConfig -->
@filamentScripts
<!-- @livewireScripts -->
<!-- @livewireScriptConfig -->
If I remove the comments it works. And I think @livewireScriptConfig is not need either because if I add it then it doesn't work @awcodes : https://filamentphp.com/docs/3.x/notifications/upgrade-guide#javascript-assets
8 replies
FFilament
Created by @nasilemak on 1/14/2024 in #❓┊help
Does @livewireScripts directive still need to be included when using @filamentScripts?
I did this too because if I remove @livewireScripts, some components doesn't work, like Tabs, Wizard, etc.
8 replies
FFilament
Created by Tieme on 2/11/2024 in #❓┊help
Enum select with live() on Create and Edit form
If you want to support ->multiple() selects, you could even do it using array_intersect() :
public function isEqualEnum(mixed $value, array $toBeEqual): bool
{
if ($value === null) {
return false;
}

if (is_array($value)) { // Here, we handle the case !
return count(array_intersect($value, $toBeEqual)) > 0;
}

if (is_string($value)) {
$enumValue = $value;
} elseif (is_object($value) && property_exists($value, 'value')) {
$enumValue = $value->value;
} else {
return false;
}

return in_array($enumValue, $toBeEqual, true);
}
public function isEqualEnum(mixed $value, array $toBeEqual): bool
{
if ($value === null) {
return false;
}

if (is_array($value)) { // Here, we handle the case !
return count(array_intersect($value, $toBeEqual)) > 0;
}

if (is_string($value)) {
$enumValue = $value;
} elseif (is_object($value) && property_exists($value, 'value')) {
$enumValue = $value->value;
} else {
return false;
}

return in_array($enumValue, $toBeEqual, true);
}
7 replies
FFilament
Created by Tieme on 2/11/2024 in #❓┊help
Enum select with live() on Create and Edit form
Great solution @sadiqgoni13 ! On my side, I only use string back enums, so I made something similar but using a FilamentService with isEqualEnum() method :
/**
* Useful for Filament forms that sometimes parse enums as strings and sometimes as objects.
*
* @param mixed $value
* @param string|list<string> $toBeEqual
* @return boolean
*/
public function isEqualEnum(mixed $value, string|array $toBeEqual): bool
{
if ($value === null) {
return false;
}

if (is_string($value)) {
$enumValue = $value;
} elseif (is_object($value) && property_exists($value, 'value')) {
$enumValue = $value->value;
} else {
return false;
}

if (is_string($toBeEqual)) {
return $enumValue === $toBeEqual;
}

return in_array($enumValue, $toBeEqual, true);
}
/**
* Useful for Filament forms that sometimes parse enums as strings and sometimes as objects.
*
* @param mixed $value
* @param string|list<string> $toBeEqual
* @return boolean
*/
public function isEqualEnum(mixed $value, string|array $toBeEqual): bool
{
if ($value === null) {
return false;
}

if (is_string($value)) {
$enumValue = $value;
} elseif (is_object($value) && property_exists($value, 'value')) {
$enumValue = $value->value;
} else {
return false;
}

if (is_string($toBeEqual)) {
return $enumValue === $toBeEqual;
}

return in_array($enumValue, $toBeEqual, true);
}
And then in my form I inject the service with the boot() method :
private FilamentService $service;

public function boot(FilamentService $service): void
{
$this->service = $service;
}
private FilamentService $service;

public function boot(FilamentService $service): void
{
$this->service = $service;
}
And use it like that :
Components\Select::make('ethnicity')
->native(false)
->searchable()
->allowHtml()
->options(EthnicityEnum::selectHtmlOptions())
->default(EthnicityEnum::EUROPEAN_WHITE)
->live(debounce: 1000)
->required(),
Components\TextInput::make('ethnicity_details')
->visible(fn (Get $get) => $this->service->isEqualEnum($get('ethnicity'), [EthnicityEnum::OTHER->value]))
->required(),
Components\Select::make('ethnicity')
->native(false)
->searchable()
->allowHtml()
->options(EthnicityEnum::selectHtmlOptions())
->default(EthnicityEnum::EUROPEAN_WHITE)
->live(debounce: 1000)
->required(),
Components\TextInput::make('ethnicity_details')
->visible(fn (Get $get) => $this->service->isEqualEnum($get('ethnicity'), [EthnicityEnum::OTHER->value]))
->required(),
In this example, the ethnicity_details field is visible only if ethnicity value is EthnicityEnum::OTHER.
7 replies
FFilament
Created by Tieme on 2/11/2024 in #❓┊help
Enum select with live() on Create and Edit form
Same problem here ! Up 🤚
7 replies
FFilament
Created by Benjamin on 9/14/2024 in #❓┊help
How to customize select option label (different when open/closed)
Here is my solution, if anyone else want to use it (@jawaad) : In my EthnicityEnum.php
public function getLabel(): string
{
return match ($this) {
self::EUROPEAN_WHITE => <<<HTML
<div class="flex flex-col">
<span>Européen/Blanc</span>
<span class="text-xs text-gray-500 __hidden-in-select text-wrap">
(Caucasien, Américains du Nord, Canadiens, Australiens)
</span>
</div>
HTML,
self::OTHER => 'Autre',
};
}
public function getLabel(): string
{
return match ($this) {
self::EUROPEAN_WHITE => <<<HTML
<div class="flex flex-col">
<span>Européen/Blanc</span>
<span class="text-xs text-gray-500 __hidden-in-select text-wrap">
(Caucasien, Américains du Nord, Canadiens, Australiens)
</span>
</div>
HTML,
self::OTHER => 'Autre',
};
}
And in my app.css :
.choices__inner .__hidden-in-select {
display: none;
}
.choices__inner .__hidden-in-select {
display: none;
}
8 replies