skip to Main Content

I have PostResource in my filament application.

Post modal schema

Posts
    - id
    - title
    - slug
    - description
    - created_by
    - status

Now, whenever I create a new post and it redirects to the Edit page and URL accessing like http://127.0.0.1"8000/posts/1/edit.
but can we add a slug in the URL?

Excepted URL: http://127.0.0.1"8000/posts/<SLUG>/edit

In my PostResource the routes

public static function getPages(): array
{
    return [
        'index' => PagesListPosts::route('/'),
        'create' => PagesCreatePost::route('/create'),
        // here, it binding route model, I want to change with slug
        'edit' => PagesEditPost::route('/{record}/edit'),
    ];
}

2

Answers


  1. You should read basic Laravel documentation

    Login or Signup to reply.
  2. It’s simple, is that…

    In your PostResource you need to add ->url() and as a route parameter add $record->slug.

    
    TablesActionsEditAction::make()
        ->url(fn (Model $record): string => static::getUrl('edit', ['record' => $record->slug])),
    
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search