DEV Community

Süleyman Özgür Özarpacı
Süleyman Özgür Özarpacı

Posted on • Updated on

How FilamentPHP Naming Resources and How to Get URL

In FilamentPHP, resources are associated with pages. By default, these pages are named using the format filament.resources.[RESOURCE_PLURAL_NAME].[PAGE_NAME]. For instance, the index page of a ProductResource would be filament.resources.products.index.

To generate a URL, you can utilize the route helper as follows:

route('filament.resources.products.index')
Enter fullscreen mode Exit fullscreen mode

However, I would recommend using the approach preferred by FilamentPHP, which is:

ProductResource::getUrl('edit', ['record' => $record])
Enter fullscreen mode Exit fullscreen mode

This ensures consistency with FilamentPHP's conventions.

Let's make an "Go To Product" action button with this:

Tables\Actions\Action::make('go_to_product')
    ->icon('heroicon-o-pencil-alt')
    ->url(fn (Model $record): string => ProductResource::getUrl('edit', ['record' => $record])),
Enter fullscreen mode Exit fullscreen mode

This button will be redirect user to product's edit page.

Top comments (3)

Collapse
 
koadamso profile image
Adama

Thank you very much for this post

Collapse
 
biostate profile image
Süleyman Özgür Özarpacı

You're welcome.

Collapse
 
v_calaca profile image
Vinícius Calaça Lemos

How do I do this in a --simple Resource??