DEV Community

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

Posted on • Edited on

4

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??

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay