Benjamin
Benjamin
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
FFilament
Created by Benjamin on 9/14/2024 in #❓┊help
How to customize select option label (different when open/closed)
Okay thanks !
8 replies
FFilament
Created by Benjamin on 9/14/2024 in #❓┊help
How to customize select option label (different when open/closed)
Any hint ? If it can help, here is my enum code :
<?php

declare(strict_types=1);

namespace App\Enums;

use Filament\Support\Contracts\HasLabel;

enum EthnicityEnum: string implements HasLabel
{
case AFRICAN_BLACK = 'african_black';
case ASIAN = 'asian';
case EUROPEAN_WHITE = 'european_white';
case HISPANO_LATINO = 'hispano_latino';
case MIDDLE_EAST_NORTH_AFRICA = 'middle_east_north_africa';
case INDIGENOUS_AMERICAS = 'indigenous_americas';
case METIS_MIXED = 'metis_mixed';
case OCEANIAN = 'oceanian';
case CARIBBEAN = 'caribbean';
case OTHER = 'other';

public function getLabel(): string
{
return match ($this) {
self::AFRICAN_BLACK => 'Africain/Noir',
self::ASIAN => 'Asiatique',
self::EUROPEAN_WHITE => <<<HTML
<div class="flex flex-col">
<span>Européen/Blanc</span>
<span class="text-xs text-gray-500 text-wrap">
(Caucasien, Américains du Nord, Canadiens, Australiens)
</span>
</div>
HTML,
self::HISPANO_LATINO => 'Hispano/Latino',
self::MIDDLE_EAST_NORTH_AFRICA => 'Moyen-Orient et Afrique du Nord',
self::INDIGENOUS_AMERICAS => 'Amérindien/Autochtone des Amériques',
self::METIS_MIXED => 'Métis/Mixte (veuillez préciser)',
self::OCEANIAN => 'Océanien (Polynésien, Mélanésien, etc.)',
self::CARIBBEAN => 'Caribéen',
self::OTHER => 'Autre',
};
}
}
<?php

declare(strict_types=1);

namespace App\Enums;

use Filament\Support\Contracts\HasLabel;

enum EthnicityEnum: string implements HasLabel
{
case AFRICAN_BLACK = 'african_black';
case ASIAN = 'asian';
case EUROPEAN_WHITE = 'european_white';
case HISPANO_LATINO = 'hispano_latino';
case MIDDLE_EAST_NORTH_AFRICA = 'middle_east_north_africa';
case INDIGENOUS_AMERICAS = 'indigenous_americas';
case METIS_MIXED = 'metis_mixed';
case OCEANIAN = 'oceanian';
case CARIBBEAN = 'caribbean';
case OTHER = 'other';

public function getLabel(): string
{
return match ($this) {
self::AFRICAN_BLACK => 'Africain/Noir',
self::ASIAN => 'Asiatique',
self::EUROPEAN_WHITE => <<<HTML
<div class="flex flex-col">
<span>Européen/Blanc</span>
<span class="text-xs text-gray-500 text-wrap">
(Caucasien, Américains du Nord, Canadiens, Australiens)
</span>
</div>
HTML,
self::HISPANO_LATINO => 'Hispano/Latino',
self::MIDDLE_EAST_NORTH_AFRICA => 'Moyen-Orient et Afrique du Nord',
self::INDIGENOUS_AMERICAS => 'Amérindien/Autochtone des Amériques',
self::METIS_MIXED => 'Métis/Mixte (veuillez préciser)',
self::OCEANIAN => 'Océanien (Polynésien, Mélanésien, etc.)',
self::CARIBBEAN => 'Caribéen',
self::OTHER => 'Autre',
};
}
}
8 replies
FFilament
Created by raheel3031 on 9/14/2024 in #❓┊help
These credentials do not match our records.
How ? May be useful for me next time
10 replies
FFilament
Created by raheel3031 on 9/14/2024 in #❓┊help
These credentials do not match our records.
@raheel3031 Hmm I tried various commands, maybe try : - php artisan optimize:clear - php artisan filament:optimize-clear - composer dump-autoload
10 replies
FFilament
Created by raheel3031 on 9/14/2024 in #❓┊help
These credentials do not match our records.
I had this error this morning and composer update solved it @raheel3031 😉
10 replies
FFilament
Created by Benjamin on 9/14/2024 in #❓┊help
How to customize select option label (different when open/closed)
I didn't specify it but the label is defined in my Enum using HasLabel interface and getLabel() method.
8 replies