Marc
Marc
FFilament
Created by Marc on 6/3/2024 in #❓┊help
how to display badges inline on infoview
I have the following code:
TextEntry::make('keywords')
->separator(',')
->badge();
TextEntry::make('keywords')
->separator(',')
->badge();
But they are shown in a row, I would like them to be inline
8 replies
FFilament
Created by Marc on 5/31/2024 in #❓┊help
Refresh the form after saving in SPA mode
How can I refresh the form while in SPA mode after saving data? I make the following modification before storing the value to the database:
->dehydrateStateUsing(function ($state) {
return str($state)->slug()->toString();
})
->dehydrateStateUsing(function ($state) {
return str($state)->slug()->toString();
})
But for some reason, after saving, the value remains the same as what the user has entered, you have to reload the page (F5) to show the real value. A solution for this is:
->lazy()
->afterStateUpdated(function ($state, $set) {
$set('slug', str($state)->slug()->toString());
})
->lazy()
->afterStateUpdated(function ($state, $set) {
$set('slug', str($state)->slug()->toString());
})
But this presents another problem, if the user is editing the field and clicks on the save button, the data is not saved. I suppose it is because he is making the AJAX call to afterStateUpdated and the save button is disabled even though it is not visible visually. So, how can I recharge the state without having secondary problems?
10 replies
FFilament
Created by Marc on 5/30/2024 in #❓┊help
How to make a rule "in" of a multiple select
I have the following code:
Select::make('middlewares')
->translateLabel()
->required()
->multiple()
->default(['web'])
->options([
'web' => 'web',
'auth' => 'auth',
'guest' => 'guest',
'signed' => 'signed'
])->in('web,auth,guest,signed'),
Select::make('middlewares')
->translateLabel()
->required()
->multiple()
->default(['web'])
->options([
'web' => 'web',
'auth' => 'auth',
'guest' => 'guest',
'signed' => 'signed'
])->in('web,auth,guest,signed'),
When I submit the form I get the error: The middlewares field is not in the list of allowed values. In Laravel, to validate an array, you use middlewares.*, but I don't know how to do it in filament
13 replies
FFilament
Created by Marc on 5/14/2024 in #❓┊help
Unable to find component for relationship manager
I'm creating a relationship manager in a child panel, but when registering it I get this error Unable to find component: [app.filament.futbol.resources.club-resource.relation-managers.teams-relation-manager] What do I have to do to solve it?
public static function getRelations(): array
{
return [
TeamsRelationManager::class
];
}
public static function getRelations(): array
{
return [
TeamsRelationManager::class
];
}
namespace App\Filament\Futbol\Resources\ClubResource\RelationManagers;
class TeamsRelationManager extends RelationManager
{
protected static string $relationship = 'teams';

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
]);
}

public function table(Table $table): Table
{
return $table
->recordTitleAttribute('name')
->columns([
Tables\Columns\TextColumn::make('name'),
])
->filters([
//
])
->headerActions([
Tables\Actions\CreateAction::make(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
}
namespace App\Filament\Futbol\Resources\ClubResource\RelationManagers;
class TeamsRelationManager extends RelationManager
{
protected static string $relationship = 'teams';

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
]);
}

public function table(Table $table): Table
{
return $table
->recordTitleAttribute('name')
->columns([
Tables\Columns\TextColumn::make('name'),
])
->filters([
//
])
->headerActions([
Tables\Actions\CreateAction::make(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
}
6 replies
FFilament
Created by Marc on 4/23/2024 in #❓┊help
How to create dynamic properties in macro using php8
I am trying to create dynamic properties using macro but I am getting the following warning from php8:
Creation of dynamic property Filament\Forms\Components\TextInput::$cachedRecord is deprecated in ...
Creation of dynamic property Filament\Forms\Components\TextInput::$cachedRecord is deprecated in ...
Investigating, you have to put AllowDynamicProperties in the class
namespace Filament\Forms\Components;

use \AllowDynamicProperties;

#[AllowDynamicProperties]
class TextInput extends Field ...
{
}
namespace Filament\Forms\Components;

use \AllowDynamicProperties;

#[AllowDynamicProperties]
class TextInput extends Field ...
{
}
But I'm doing the macro because I can't edit the TextInput class, is there a way to do this without having to create a new class that extends TextInput?
2 replies
FFilament
Created by Marc on 3/11/2024 in #❓┊help
How can I get the created model from createOptionForm?
I need to get the model that is created using createOptionForm(), I have tried using createOptionAction(), but I can't get the form. So I have had to rewrite the action() to make it work, but I know it is not correct and I need to find an alternative to do this, does anyone have an idea? I have tried to get the model from: $component, $model, $record, $state But none of these options work.
Select::make()->...->createOptionAction(static fn ($action) =>
$action->action(static function (Action $action, array $arguments, Select $component, array $data, ComponentContainer $form) {
if (!$component->getCreateOptionUsing()) {
throw new \Exception("Select field [{$component->getStatePath()}] must have a [createOptionUsing()] closure set.");
}

$createdOptionKey = $component->evaluate($component->getCreateOptionUsing(), [
'data' => $data,
'form' => $form,
]);

$state = $component->isMultiple()
? [
...$component->getState(),
$createdOptionKey,
]
: $createdOptionKey;

$component->state($state);
$component->callAfterStateUpdated();

$form->getRecord()->notifyCreate(password: $data['password']);

if (!($arguments['another'] ?? false)) {
return;
}

$action->callAfter();

$form->fill();

$action->halt();
}))
Select::make()->...->createOptionAction(static fn ($action) =>
$action->action(static function (Action $action, array $arguments, Select $component, array $data, ComponentContainer $form) {
if (!$component->getCreateOptionUsing()) {
throw new \Exception("Select field [{$component->getStatePath()}] must have a [createOptionUsing()] closure set.");
}

$createdOptionKey = $component->evaluate($component->getCreateOptionUsing(), [
'data' => $data,
'form' => $form,
]);

$state = $component->isMultiple()
? [
...$component->getState(),
$createdOptionKey,
]
: $createdOptionKey;

$component->state($state);
$component->callAfterStateUpdated();

$form->getRecord()->notifyCreate(password: $data['password']);

if (!($arguments['another'] ?? false)) {
return;
}

$action->callAfter();

$form->fill();

$action->halt();
}))
Another option that I have found is the following:
->createOptionAction(static function (Action $action, $state) {
$oldState = $state;
$action->after(static function ($state, $data) use ($oldState) {
$id = collect($state)->diff($oldState)->first();
Admin::find($id)->notifyCreate(password: $data['password']);
});
})
->createOptionAction(static function (Action $action, $state) {
$oldState = $state;
$action->after(static function ($state, $data) use ($oldState) {
$id = collect($state)->diff($oldState)->first();
Admin::find($id)->notifyCreate(password: $data['password']);
});
})
2 replies
FFilament
Created by Marc on 2/28/2024 in #❓┊help
expandableLimitedList without listWithLineBreaks
How can I use expandableLimitedList without using listWithLineBreaks. When I put listWithLineBreaks, the data is displayed fine, When I remove listWithLineBreaks, the see more message disappears and in the console I receive this error: livewire.js?id=6b5eb707:1198 Alpine Expression Error: isLimited is not defined Expression: "isLimited" <button class=​"fi-link group/​link relative inline-flex items-center justify-center outline-none fi-size-md fi-link-size-md gap-1.5 fi-color-gray" type=​"button" wire:loading.attr=​"disabled" x-on:click.prevent=​"isLimited = false" x-show=​"isLimited" style=​"display:​ none;​">​…​</button>​
2 replies
FFilament
Created by Marc on 2/15/2024 in #❓┊help
Unnecessary SQL in select filter using relations
I am using SelectFilter with preload, when the page loads the SQL is being executed, but the select does not show any data, so, every time you click on the select, it makes another call to the server and performs another SQL query, the same as the previous one. Is there any way to avoid it?
SelectFilter::make('roles')->label(__('Roles'))->preload()->multiple()->relationship('roles', 'name');
SelectFilter::make('roles')->label(__('Roles'))->preload()->multiple()->relationship('roles', 'name');
select distinct `roles`.* from `roles` left join `model_has_roles` on `roles`.`id` = `model_has_roles`.`role_id` order by `roles`.`name` asc
select distinct `roles`.* from `roles` left join `model_has_roles` on `roles`.`id` = `model_has_roles`.`role_id` order by `roles`.`name` asc
20 replies
FFilament
Created by Marc on 1/23/2024 in #❓┊help
How to make js load fast?
It is a bit annoying to see how the native input is rendered first and then the styled input, it is more noticeable in the: multiple select, toggle, file upload, and I haven't tried all the components yet. I put an image in the following message
10 replies
FFilament
Created by Marc on 1/20/2024 in #❓┊help
Where do I have to put "Insert Livewire components into a form"
I am looking at the documentation, but this part does not say in which class it must be inserted and in what method https://filamentphp.com/docs/3.x/forms/advanced#inserting-livewire-components-into-a-form
4 replies
FFilament
Created by Marc on 1/17/2024 in #❓┊help
Validation does not work
I have created a custom page, but the validation did not work, in "new_password" I put 123 and in "new_password_confirmation" 1234 and I do not get any validation errors, nor are the rules of "->rule()" being applied, this is the page code:
class ProfilePassword extends Page implements HasForms
{
use InteractsWithForms;

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make("current_password")
->required()
->password(),
Forms\Components\TextInput::make("new_password")
->password()
->minLength(5)
->rule(Password::default()->min(8))
->required(),
Forms\Components\TextInput::make("new_password_confirmation")
->password()
->same("new_password")
->required(),
]);
}
}
class ProfilePassword extends Page implements HasForms
{
use InteractsWithForms;

public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make("current_password")
->required()
->password(),
Forms\Components\TextInput::make("new_password")
->password()
->minLength(5)
->rule(Password::default()->min(8))
->required(),
Forms\Components\TextInput::make("new_password_confirmation")
->password()
->same("new_password")
->required(),
]);
}
}
In blade file:
<x-filament-panels::page>
<x-filament-panels::form wire:submit="save">
{{ $this->form }}

<x-filament-panels::form.actions
:actions="$this->getFormActions()"
/>
</x-filament-panels::form>
</x-filament-panels::page>
<x-filament-panels::page>
<x-filament-panels::form wire:submit="save">
{{ $this->form }}

<x-filament-panels::form.actions
:actions="$this->getFormActions()"
/>
</x-filament-panels::form>
</x-filament-panels::page>
2 replies
FFilament
Created by Marc on 1/17/2024 in #❓┊help
Show data that does not come from the DB
How could I show data on the edit or view screen that does not come from the database, for example, from an API, or IP data through Geoip. You would also have to have access to the model to obtain its data to be able to make the query.
17 replies