Adysone
Adysone
FFilament
Created by Adysone on 10/22/2024 in #❓┊help
Custom resource route with extra parameters
Hello, I'd like to make this work:
class ContactResource extends Resource
{
// (...)

public static function getPages(): array
{
return [
'index' => Pages\ListContacts::route('/{contact_type}/'),
'create' => Pages\CreateContact::route('/{contact_type}/create'),
'edit' => Pages\EditContact::route('/{contact_type}/{record}/edit'),
];
}

// (...)
}
class ContactResource extends Resource
{
// (...)

public static function getPages(): array
{
return [
'index' => Pages\ListContacts::route('/{contact_type}/'),
'create' => Pages\CreateContact::route('/{contact_type}/create'),
'edit' => Pages\EditContact::route('/{contact_type}/{record}/edit'),
];
}

// (...)
}
I'd like to preserve the "contact_type" parameter when I edit, create or delete a record in the Contact table. In the navigation menu, I generate links dynamically according to "Contact types" created by the superadmin, so I came with this in the AdminPanelProvider (with a question in it):
$thirdPartyContactTypeNavigationItems = ContactType::orderBy('label')
->get()
->map(function (ContactType $contactType): NavigationItem {
return NavigationItem::make($contactType->label)
->icon('heroicon-o-users')
->group(__('ThirdParty/main.third_party'))
->isActiveWhen(function () use ($contactType): bool {
// How can I get the current value of contact_type?
})
->url(fn (): string => ContactResource::getUrl(
parameters: ['contact_type' => $contactType->code]
));
})
->all();

return $panel
// (...)
->navigationItems($thirdPartyContactTypeNavigationItems);
$thirdPartyContactTypeNavigationItems = ContactType::orderBy('label')
->get()
->map(function (ContactType $contactType): NavigationItem {
return NavigationItem::make($contactType->label)
->icon('heroicon-o-users')
->group(__('ThirdParty/main.third_party'))
->isActiveWhen(function () use ($contactType): bool {
// How can I get the current value of contact_type?
})
->url(fn (): string => ContactResource::getUrl(
parameters: ['contact_type' => $contactType->code]
));
})
->all();

return $panel
// (...)
->navigationItems($thirdPartyContactTypeNavigationItems);
Thanks!
2 replies
FFilament
Created by Adysone on 10/8/2024 in #❓┊help
Prefix before icon in tables
No description
4 replies
FFilament
Created by Adysone on 9/16/2024 in #❓┊help
Display breadcrumbs and title of the page in topbar
No description
8 replies
FFilament
Created by Adysone on 8/1/2024 in #❓┊help
Livewire component grid in template does not render as grid col, unless use col-start-*
No description
17 replies
FFilament
Created by Adysone on 7/29/2024 in #❓┊help
Update section heading programmatically
Hello, Is it possible to update a section heading programmatically? Or display a form field in it? I would like to display a "total cost" calculated with other fields of the form, in the heading of a section. The issue is that I put a value in the heading like so:
Forms\Components\Section::make()
->heading(fn(Get $get): string => (string) $get('total_cost'))
Forms\Components\Section::make()
->heading(fn(Get $get): string => (string) $get('total_cost'))
But my "total_cost" field is not defined on a creation form, because it's calculated after some fields are updated. How can I force the update of the heading? IS there a "boot" method on form builder?
12 replies
FFilament
Created by Adysone on 7/25/2024 in #❓┊help
Test Livewire assertDispatched and assertSee after event dispatched
Hello, I have the following field :
Forms\Components\Select::make('licenses')
->label(__('vmc.licenses'))
->preload()
->relationship('licenses', 'name', fn (Builder $query) => $query->orderBy('name'))
->multiple()
->searchable()
->live()
->afterStateHydrated(function (Component $livewire, ?array $state) {
$livewire->dispatch('updatedSelectedLicenses', selectedLicenses: $state);
})
->afterStateUpdated(function (Component $livewire, ?array $state) {
$livewire->dispatch('updatedSelectedLicenses', selectedLicenses: $state);
})
Forms\Components\Select::make('licenses')
->label(__('vmc.licenses'))
->preload()
->relationship('licenses', 'name', fn (Builder $query) => $query->orderBy('name'))
->multiple()
->searchable()
->live()
->afterStateHydrated(function (Component $livewire, ?array $state) {
$livewire->dispatch('updatedSelectedLicenses', selectedLicenses: $state);
})
->afterStateUpdated(function (Component $livewire, ?array $state) {
$livewire->dispatch('updatedSelectedLicenses', selectedLicenses: $state);
})
And I have the following test :
$license = License::factory()->create(['cost' => 22.1234]);

Livewire::test(CreateVirtualMachine::class)
->assertFormFieldExists('licenses')
->set('data.licenses', [$license->id])
->assertDispatched('updatedSelectedLicenses', ['selectedLicenses' => [$license->id]])
->assertSee('22,12');
$license = License::factory()->create(['cost' => 22.1234]);

Livewire::test(CreateVirtualMachine::class)
->assertFormFieldExists('licenses')
->set('data.licenses', [$license->id])
->assertDispatched('updatedSelectedLicenses', ['selectedLicenses' => [$license->id]])
->assertSee('22,12');
When I run my test, I have the following fails :
Failed asserting that an event [updatedSelectedLicenses] was fired with parameters: [{"selectedLicenses":[2]}]
Failed asserting that an event [updatedSelectedLicenses] was fired with parameters: [{"selectedLicenses":[2]}]
and
Failed asserting that '<bunch of html>' [UTF-8](length: 83059) contains "22,12" [ASCII](length: 5).
Failed asserting that '<bunch of html>' [UTF-8](length: 83059) contains "22,12" [ASCII](length: 5).
1. I don't understand why the first assertion fails and why the parameters aren't correct as I send the $state when I dispatch the event. 2. I don't understand why 22,12 is not in the HTML as when I test it in my browser, it works like a charm.
4 replies
FFilament
Created by Adysone on 6/13/2024 in #❓┊help
Update viewfield state with placeholder addition values
No description
11 replies