*
*
FFilament
Created by * on 9/7/2023 in #❓┊help
Inserting pivot data without RelationManager
I have a multiple select on an edit page, has a belongsToMany() relationship. I want to inject something to be saved in a column in the pivot table. I found out that the relationship is saved in HasState::getState(), but could not find a way to inject additional data to it. Tried mutateFormDataBeforeSave() in the EditThing component, but that gets called after getState(), so no effect. Any help would be appreciated.
14 replies
FFilament
Created by * on 8/29/2023 in #❓┊help
using hiddenOn and hidden in conjunction
Currently, there's no way of achieving this, as the last chained call will override the previous. something like this, quite understandably will not work:
->hiddenOn('create')
->hidden(fn () => someLogicReturningABool())
->hiddenOn('create')
->hidden(fn () => someLogicReturningABool())
What I'm trying to achieve is, hide a tab in a form on create, and on edit, have a closure to run some custom logic to hide or show it. The only solution I can think of is duplicating the code for the hiddenOn method in the hidden closure, which is less than ideal. Any suggestions on how to tackle this?
5 replies
FFilament
Created by * on 8/15/2023 in #❓┊help
Testing select field options
I've implemented some logic to update the query in a select field using modifyQueryUsing(closure) Is there a way to test this logic? Maybe using a closure with assertFormFieldExists()? Like...
livewire(CreateUser::class)
->assertFormFieldExists('organisations', function (Select $input) {
return /* some logic here */;
});
livewire(CreateUser::class)
->assertFormFieldExists('organisations', function (Select $input) {
return /* some logic here */;
});
I've attempted to get the options using the $input closure param above with no luck. Note: My select is multiple() and has preload() Any help and/or insight appreciated.
10 replies
FFilament
Created by * on 8/7/2023 in #❓┊help
formatStateUsing() and a nullable boolean column
I have a nullable boolean column in a table like:
$table->boolean('decision')->nullable();
$table->boolean('decision')->nullable();
In my Filament table, I'm trying to display 'Pending' for the null value and 'Accepted' or 'Rejected' correspondingly for true and false I do not get any $state or Model $record for the null values at all.
TextColumn::make('decision')
->badge()
->formatStateUsing(function (Model $record) {
dump($record);
})
...
TextColumn::make('decision')
->badge()
->formatStateUsing(function (Model $record) {
dump($record);
})
...
will not dump anything at all, but works as expected for the non-null values. same with
TextColumn::make('decision')
->badge()
->formatStateUsing(function (string $state) {
dump($state)
})
...
TextColumn::make('decision')
->badge()
->formatStateUsing(function (string $state) {
dump($state)
})
...
Any insight would be appreciated.
12 replies
FFilament
Created by * on 8/2/2023 in #❓┊help
What is the best way of applying custom middleware to the registration page?
I want to apply one of my own middleware classes to the registration page after adding in ->registration() in a panel service provider. Tried adding in the HasRoutes concern in a registration page component which extends Filament\Pages\Auth\Register\ and implemented getRouteMiddleware() and routes() with no luck.
5 replies
FFilament
Created by * on 7/26/2023 in #❓┊help
redirect() in action, strange behaviour
I've got the following test:
it('bla', function () {
$invitationData = \App\Models\UserInvitation::factory()->make()->toArray();

data_forget($invitationData, 'uuid');

$invitationData['name'] = fake()->name;
$invitationData['email'] = fake()->email;
$invitationData['company'] = fake()->company;
$invitationData['address'] = fake()->address;
$invitationData['postcode'] = fake()->postcode;

$invitation = (new StoreUserInvitation())->execute(invitationData: $invitationData);

livewire(UserInvitationResource\Pages\ViewUserInvitation::class, [
'record' => $invitation->id,
])->callPageAction('resend');

$expectedNewInvitationData = data_get($invitation, [
'name',
'email',
'company',
'address',
'postcode',
]);

$expectedNewInvitationData['status'] = UserInvitationStatus::PENDING;

$this->assertDatabaseCount(\App\Models\UserInvitation::class, 2);
});
it('bla', function () {
$invitationData = \App\Models\UserInvitation::factory()->make()->toArray();

data_forget($invitationData, 'uuid');

$invitationData['name'] = fake()->name;
$invitationData['email'] = fake()->email;
$invitationData['company'] = fake()->company;
$invitationData['address'] = fake()->address;
$invitationData['postcode'] = fake()->postcode;

$invitation = (new StoreUserInvitation())->execute(invitationData: $invitationData);

livewire(UserInvitationResource\Pages\ViewUserInvitation::class, [
'record' => $invitation->id,
])->callPageAction('resend');

$expectedNewInvitationData = data_get($invitation, [
'name',
'email',
'company',
'address',
'postcode',
]);

$expectedNewInvitationData['status'] = UserInvitationStatus::PENDING;

$this->assertDatabaseCount(\App\Models\UserInvitation::class, 2);
});
ViewUserInvitation.php related parts are:
protected function getActions(): array
{
return [
Action::make('resend')->action('resendInvitation'),
];
}
protected function getActions(): array
{
return [
Action::make('resend')->action('resendInvitation'),
];
}
and
public function resendInvitation()
{
$newInvitationData = Arr::except($this->record->toArray(), [
'id',
'uuid',
'token',
'expires_at',
'status',
'created_at',
'updated_at',
]);

$invitation = (new StoreUserInvitation())->execute(invitationData: $newInvitationData);

return redirect()->route('filament.resources.user-invitations.view', [
'record' => $invitation,
]);
}
public function resendInvitation()
{
$newInvitationData = Arr::except($this->record->toArray(), [
'id',
'uuid',
'token',
'expires_at',
'status',
'created_at',
'updated_at',
]);

$invitation = (new StoreUserInvitation())->execute(invitationData: $newInvitationData);

return redirect()->route('filament.resources.user-invitations.view', [
'record' => $invitation,
]);
}
The first assertion in the test passes. The second fails with count being 3 !== 2 But, when I remove the return redirect().... , the test passes as expected.
7 replies