Epko
Epko
FFilament
Created by xoshbin on 11/21/2024 in #❓┊help
mutateRelationshipDataBeforeCreateUsing in Filament's Repeater supposed to return an array of items?
Never used this, but I think the method is called separately for each entry. So dd() would only show the first one.
6 replies
FFilament
Created by Vp on 5/6/2024 in #❓┊help
How to eager load relationship inside infolist repeatable entry
Thanks Mark, your solution almost worked, but when I also have an Action button on the InfoList, it triggers the lazy loading error once again. Turns out this is the way to do it:
$record = $infolist->getRecord()->load('rel.subrel');
return $infolist
->record($record)
$record = $infolist->getRecord()->load('rel.subrel');
return $infolist
->record($record)
And if you use an Action in the Infolist that also uses a relationship that should be eager loaded:
->form(function (SomeModel $record) {
$record->load('rel.subrel');
->form(function (SomeModel $record) {
$record->load('rel.subrel');
26 replies
FFilament
Created by Leepay Lon (Dmitry) on 11/6/2023 in #❓┊help
Trim each input
Added this to AppServiceProvider:
use Filament\Forms;
public function boot(): void
{
Forms\Components\TextInput::configureUsing(function (Forms\Components\TextInput $textInput): void {
$textInput
->dehydrateStateUsing(function (?string $state): ?string {
return is_string($state) ? trim($state) : $state;
});
});
}
use Filament\Forms;
public function boot(): void
{
Forms\Components\TextInput::configureUsing(function (Forms\Components\TextInput $textInput): void {
$textInput
->dehydrateStateUsing(function (?string $state): ?string {
return is_string($state) ? trim($state) : $state;
});
});
}
Works perfectly. Thanks for the hint @awcodes !
7 replies
FFilament
Created by Leepay Lon (Dmitry) on 11/6/2023 in #❓┊help
Trim each input
This is indeed working, and probably the best solution. I find it strange this is not the default behaviour in Filament, as it is the default behaviour in Laravel (https://laravel.com/docs/11.x/validation#a-note-on-optional-fields). For anyone having the same issue, this is how I implemented it (thanks to the suggestion of @toeknee):
protected function mutateFormDataBeforeSave(array $data): array
{
foreach ($data as $key => $value) {
$data[$key] = is_string($value) ? trim($value) : $value;
}
return $data;
}
protected function mutateFormDataBeforeSave(array $data): array
{
foreach ($data as $key => $value) {
$data[$key] = is_string($value) ? trim($value) : $value;
}
return $data;
}
But I have to repeat this in every Edit page.
7 replies