Benjamin
Benjamin
FFilament
Created by Benjamin on 1/20/2025 in #❓┊help
Performance issue with BulkAction : selectedRecords (only IDs, not Eloquent?)
Hi guys, I'm working on a Filament app and I need to add some exports features. We have a lot of tables and data, so both the official Filament Export action and Dennis Koch package are not suitable for us. I'm using Laravel Excel and DB Query without Eloquent, but I wish I could offer my users a way to filter the data before export them. For that, I'm trying to use BulkAction, however the $selectedRecords is an Eloquent collection and when using the Select All it makes my app crashes. Is that a way for the table select option to only retrieve an array of ID and not load the entire Eloquent collection? I know this is a very specific request and maybe it's not possible, but I just want to be sure before switching to a custom solution.
2 replies
FFilament
Created by Benjamin on 11/28/2024 in #❓┊help
Table filters : column not found, why ?
Hi everyone ! Is someone here capable to explain how/why table filters have no access to table query column ? For example : Let's say I have a users table with a calculated "availabilityScore" column (percentage, from 0 to 100). If I want a filter for that "availabilityScore", I can't just use ->where('availabilityScore', '>', 10) because it will throw a column not found error. Why filters are not just modifying the table query ? I'm sure there is good reasons, I just need to understand 🙂 Thanks !
7 replies
FFilament
Created by Benjamin on 11/19/2024 in #❓┊help
Why wire:dirty not working with <x-filament::> components ?
Hi guys ! I'm writing some custom Livewire components and I'm using some Filament blade components inside of them to keep the UI consistent. I'm trying to use wire:dirty on a Filament button but it doesn't work. It works on a basic HTML button, do you know why ?
<x-filament::button
wire:click="validateTimeslots"
wire:dirty.remove
>
{{ __('Confirm') }}
</x-filament::button>

<button wire:dirty.remove>
Testing
</button>
<x-filament::button
wire:click="validateTimeslots"
wire:dirty.remove
>
{{ __('Confirm') }}
</x-filament::button>

<button wire:dirty.remove>
Testing
</button>
3 replies
FFilament
Created by Benjamin on 10/22/2024 in #❓┊help
Struggling with SelectFilter with relationship() and distinct status (Enum)
Hi guys ! I want to make a filter or the abacus_status in my users table but this status is in another table user_details, linked to the users via the details() relationship. What is wrong in my code ? ERROR : Object of class App\Enums\Users\AbacusStatusEnum could not be converted to string
Tables\Filters\SelectFilter::make('abacus_status')
->label(__('Status') . ' Abacus')
->multiple()
->relationship(
name: 'details',
titleAttribute: 'abacus_status',
modifyQueryUsing: fn(Builder $query) => $query->select('abacus_status')->groupBy('abacus_status')
)
->getOptionLabelFromRecordUsing(fn(UserDetail $record) => $record->abacus_status->getLabel())
->options(AbacusStatusEnum::class)
->preload(),
Tables\Filters\SelectFilter::make('abacus_status')
->label(__('Status') . ' Abacus')
->multiple()
->relationship(
name: 'details',
titleAttribute: 'abacus_status',
modifyQueryUsing: fn(Builder $query) => $query->select('abacus_status')->groupBy('abacus_status')
)
->getOptionLabelFromRecordUsing(fn(UserDetail $record) => $record->abacus_status->getLabel())
->options(AbacusStatusEnum::class)
->preload(),
3 replies
FFilament
Created by Benjamin on 10/1/2024 in #❓┊help
Custom rule based on another field - Good way or not ?
I'm implementing a custom rule that verify that two dates are in the same year. Custom Laravel Rule
final class SameYearAs implements ValidationRule
{
public function __construct(private mixed $toCompareWith)
{}

public function validate(string $attribute, mixed $value, Closure $fail): void
{
$toCompareWith = $this->toCompareWith;
if (filled($toCompareWith)) {
$value = CarbonImmutable::parse($value);
$toCompareWith = CarbonImmutable::parse($toCompareWith);

if (!$value->isSameYear($toCompareWith)) {
$fail('Not similar year!');
}
}
}
}
final class SameYearAs implements ValidationRule
{
public function __construct(private mixed $toCompareWith)
{}

public function validate(string $attribute, mixed $value, Closure $fail): void
{
$toCompareWith = $this->toCompareWith;
if (filled($toCompareWith)) {
$value = CarbonImmutable::parse($value);
$toCompareWith = CarbonImmutable::parse($toCompareWith);

if (!$value->isSameYear($toCompareWith)) {
$fail('Not similar year!');
}
}
}
}
Filament Form schema()
Forms\Components\DatePicker::make('start_at')
->label(__('Start at'))
->beforeOrEqual('end_at')
->required(),
Forms\Components\DatePicker::make('end_at')
->label(__('End at'))
->afterOrEqual('start_at')
->rules(fn (Get $get) => [new SameYearAs($get('start_at'))])
->required(),
Forms\Components\DatePicker::make('start_at')
->label(__('Start at'))
->beforeOrEqual('end_at')
->required(),
Forms\Components\DatePicker::make('end_at')
->label(__('End at'))
->afterOrEqual('start_at')
->rules(fn (Get $get) => [new SameYearAs($get('start_at'))])
->required(),
It works, but is that right do it like that ? I started using DataAwareRule but the problem is that the form data are stored in a "sub-array" and therefore if I use $this->data['data']['field-name'] the rule will works with Filament (Livewire?) but not in another classic class like a Controller.
array:19 [
"data" => array:34 []
"previousUrl" => "http://admin.nanou.test/admin/missions"
"mountedActions" => []
"mountedActionsArguments" => []
"mountedActionsData" => []
"defaultAction" => null
"defaultActionArguments" => null
"componentFileAttachments" => []
"mountedFormComponentActions" => []
"mountedFormXXXX"...
"activeRelationManager" => "2"
"record" => array:29 []
"savedDataHash" => null
]
array:19 [
"data" => array:34 []
"previousUrl" => "http://admin.nanou.test/admin/missions"
"mountedActions" => []
"mountedActionsArguments" => []
"mountedActionsData" => []
"defaultAction" => null
"defaultActionArguments" => null
"componentFileAttachments" => []
"mountedFormComponentActions" => []
"mountedFormXXXX"...
"activeRelationManager" => "2"
"record" => array:29 []
"savedDataHash" => null
]
2 replies
FFilament
Created by Benjamin on 9/28/2024 in #❓┊help
validate() vs getState()
Hi guys ! I'm using a custom Form inside a Livewire component and I need to understand the difference between validate() and getState(). Here is my code :
public function create(): void
{
$data = $this->form->validate(); // I get validated data, without hidden fields such as `has_blabla`
$dataBis = $this->form->getState(); // I get validated data, with hidden fields such as `has_blabla`, is it normal ?
}
public function create(): void
{
$data = $this->form->validate(); // I get validated data, without hidden fields such as `has_blabla`
$dataBis = $this->form->getState(); // I get validated data, with hidden fields such as `has_blabla`, is it normal ?
}
I'm reusing form fields across multiple forms and some fields needs to be hidden (for the user + in the data), like this one :
Components\TextInput::make('has_blabla')
->label('blabla')
->required()
->visible(fn (): bool => $this->formType === FormTypeEnum::WITNESS),
Components\TextInput::make('has_blabla')
->label('blabla')
->required()
->visible(fn (): bool => $this->formType === FormTypeEnum::WITNESS),
8 replies
FFilament
Created by Benjamin on 9/14/2024 in #❓┊help
How to customize select option label (different when open/closed)
No description
8 replies
FFilament
Created by Benjamin on 9/13/2024 in #❓┊help
Modify/add colors when using Filament outside of panel
Hi guys ! I'm trying to change colors of Filament components and I was able do to it for the Panel but not for the blade component used outside such as <x-filament::link/>. I tried this in my tailwind.config.js but it doesn't work :
import preset from "./vendor/filament/support/tailwind.config.preset";

const colors = require("tailwindcss/colors");

export default {
presets: [preset],
content: [
"./app/Filament/**/*.php",
"./resources/views/**/*.blade.php",
"./vendor/filament/**/*.blade.php",
],
theme: {
extend: {
colors: {
primary: colors.cyan,
},
},
},
};
import preset from "./vendor/filament/support/tailwind.config.preset";

const colors = require("tailwindcss/colors");

export default {
presets: [preset],
content: [
"./app/Filament/**/*.php",
"./resources/views/**/*.blade.php",
"./vendor/filament/**/*.blade.php",
],
theme: {
extend: {
colors: {
primary: colors.cyan,
},
},
},
};
Anyone can help ?
3 replies
FFilament
Created by Benjamin on 7/9/2024 in #❓┊help
Widget tables - How to display results total and advanced navigation
No description
4 replies
FFilament
Created by Benjamin on 6/5/2024 in #❓┊help
DatePicker/DateTimePicker alternative with manual typing support
Does anyone here already made a custom DatePicker/DateTimePicker or found an alternative version that allow manual typing ? I really need it and I know some people already asked for it (https://github.com/filamentphp/filament/discussions/6209 and https://github.com/filamentphp/filament/discussions/6817) so maybe I don't have to do it from scratch. Edit : It' s possible to use ->type('datetime-local') , but then I lost all DatePicker great utilities such as firstDayOfWeek(), disabledDates(), minDate() and maxDate(). Yes, minDate() and maxDate() can be replaced by something like ->extraInputAttributes(['max' => now()->isoFormat('YYYY-MM-DDTHH:mm')]), but the problem is that when using TextInput with a specific type, the field is not updated when using refreshFormData and a complete page reload (F5) is necessary. Thanks 🙏
14 replies
FFilament
Created by Benjamin on 5/1/2024 in #❓┊help
Refresh my form after custom "Cancel" action
Hi guys. I created an action that allow to cancel a mission (switch status + fill cancellation related fields). Those fields are visible on my MissionResource.php only if the status is CANCELLED.
Forms\Components\Section::make(__('Cancellation'))
->schema([
Forms\Components\DateTimePicker::make('cancelled_at')
->label(__('Cancelled at'))
->displayFormat('d.m.Y H:i')
->native(false),
Forms\Components\Select::make('cancellation_type')
->label(__('Cancellation type'))
->options(CancellationTypeEnum::class)
->required(),
Forms\Components\Textarea::make('cancellation_reason')
->label(__('Cancellation reason'))
->rows(3),
])
->visible(fn (?Mission $record): bool => $record && $record->mission_status === MissionStatusEnum::CANCELLED),
Forms\Components\Section::make(__('Cancellation'))
->schema([
Forms\Components\DateTimePicker::make('cancelled_at')
->label(__('Cancelled at'))
->displayFormat('d.m.Y H:i')
->native(false),
Forms\Components\Select::make('cancellation_type')
->label(__('Cancellation type'))
->options(CancellationTypeEnum::class)
->required(),
Forms\Components\Textarea::make('cancellation_reason')
->label(__('Cancellation reason'))
->rows(3),
])
->visible(fn (?Mission $record): bool => $record && $record->mission_status === MissionStatusEnum::CANCELLED),
The problem is, when the action is performed, the fields appears but they are not fill with the data I just typed, but those that where loaded at the loading of the page. I tried to use protected $listeners = ['refreshEditMissions' => '$refresh']; on the EditMissions.php page and dispatch the event in the action, I tried to use the refreshFormData method, but nothing is working. Please help 🙏 Here is my action code : https://pastebin.com/LNDJSQt6
4 replies
FFilament
Created by Benjamin on 3/6/2024 in #❓┊help
JS error : "Livewire assets are out of date"
Hi guys, I made a few changes on my Filament app and now login isn't working anymore and I think it's related to Livewire because I have this error in the console
Livewire: The published Livewire assets are out of date
See: https://livewire.laravel.com/docs/installation#publishing-livewires-frontend-assets
Livewire: The published Livewire assets are out of date
See: https://livewire.laravel.com/docs/installation#publishing-livewires-frontend-assets
and even the password input doesn't work anymore. Do you have any advice to help me ? I'm struggling since 2 hours on it... I also tried
php artisan livewire:publish --assets
php artisan livewire:publish --assets
, then livewire is correctly loaded but the login is just redirecting me to the login page.
6 replies
FFilament
Created by Benjamin on 2/20/2024 in #❓┊help
Trying to make a custom field (for custom complex component)
No description
5 replies
FFilament
Created by Benjamin on 2/15/2024 in #❓┊help
Is there a way to trigger a RelationManager "create" action from a Widget action ?
No description
5 replies
FFilament
Created by Benjamin on 10/26/2023 in #❓┊help
Unique rule with MorphToSelect fields
Hi ! I'm trying to create a form for a "relations" polymorphic table I have in my database to manage relations between three entities (Users, Companies and Institutions). Here is the table code :
Schema::create(self::TABLE_NAME, function (Blueprint $table): void {
$table->id();
$table->bigInteger('relationable_id')->unsigned();
$table->string('relationable_type');
$table->bigInteger('target_id')->unsigned();
$table->string('target_type');
$table->string('relation_type', 45);
$table->timestamps();
$table->index('relation_type');
$table->unique(['relationable_id', 'relationable_type', 'target_type', 'relation_type'], self::TABLE_NAME . '_unique');
});
Schema::create(self::TABLE_NAME, function (Blueprint $table): void {
$table->id();
$table->bigInteger('relationable_id')->unsigned();
$table->string('relationable_type');
$table->bigInteger('target_id')->unsigned();
$table->string('target_type');
$table->string('relation_type', 45);
$table->timestamps();
$table->index('relation_type');
$table->unique(['relationable_id', 'relationable_type', 'target_type', 'relation_type'], self::TABLE_NAME . '_unique');
});
I already used ->unique() method on classic Select fields like that :
Forms\Components\Select::make('user_id')
->relationship('user', 'v_fullname')
->unique(modifyRuleUsing: function (Unique $rule) {
return $rule
->where('model_type', Company::class)
->where('model_id', $this->getOwnerRecord());
})
Forms\Components\Select::make('user_id')
->relationship('user', 'v_fullname')
->unique(modifyRuleUsing: function (Unique $rule) {
return $rule
->where('model_type', Company::class)
->where('model_id', $this->getOwnerRecord());
})
But is there any possibility define a unique() rule on MorphToSelect fields ?
Forms\Components\MorphToSelect::make('relationable')
->label('Relationable')
->types([
Forms\Components\MorphToSelect\Type::make(Company::class)
->titleAttribute('name'),
Forms\Components\MorphToSelect\Type::make(Institution::class)
->titleAttribute('name'),
]),
Forms\Components\MorphToSelect::make('relationable')
->label('Relationable')
->types([
Forms\Components\MorphToSelect\Type::make(Company::class)
->titleAttribute('name'),
Forms\Components\MorphToSelect\Type::make(Institution::class)
->titleAttribute('name'),
]),
Thanks in advance !
2 replies
FFilament
Created by Benjamin on 10/11/2023 in #❓┊help
Can't edit a resource if viewAny() is false (Model Policy)
No description
6 replies
FFilament
Created by Benjamin on 9/20/2023 in #❓┊help
From v2 to v3 : translations not working anymore for all my selects
No description
3 replies
FFilament
Created by Benjamin on 9/4/2023 in #❓┊help
Help to create a custom fields (comments)
Hi ! Is there someone here who could help me to create a custom fields list and add comments ? I followed the docs but can't make it work 😦
15 replies
FFilament
Created by Benjamin on 8/21/2023 in #❓┊help
Trying to debug : Company::setTranslation(): Argument #2 ($locale) must be of type string, null...
4 replies
FFilament
Created by Benjamin on 7/25/2023 in #❓┊help
Translatable plugin : make relationship field works
13 replies