phplaravellaravel-8laravel-routingrouteparams

Default parameter for methods in routing type resource Laravel 8


I'm trying to add default parameter to resource routing as per documentation:

Laravel doc

My code looks like:

Route::resource('flats', FlatsController::class)->parameters([
    'index' => 'test_parameter',
    'create' => 'test_parameter1',
    'update' => 'test_parameter2'
]);

But unfortunately all the time when listing the routing it gets like in the screenshot below:

routing list

Please help guide at what point do I make a mistake?


Solution

  • You have the following:

    | Methods   | route                               |
    |-----------|-------------------------------------|
    | POST      | panel/investments/flats             |
    | GET/HEAD  | panel/investments/flats             |
    | GET/HEAD  | panel/investments/flats/create      |
    | GET/HEAD  | panel/investments/flats/{flat}      |
    | PUT/PATCH | panel/investments/flats/{flat}      |
    | DELETE    | panel/investments/flats/{flat}      |
    | GET/HEAD  | panel/investments/flats/{flat}/edit |
    

    Since the only parameter is {flat} you can only rename this one as per docs:

    Route::resource('flats', FlatsController::class)->parameters([
        'flat' => 'apartment'
    ]);
    

    This results in:

    | Methods   | route                                    |
    |-----------|------------------------------------------|
    | POST      | panel/investments/flats                  |
    | GET/HEAD  | panel/investments/flats                  |
    | GET/HEAD  | panel/investments/flats/create           |
    | GET/HEAD  | panel/investments/flats/{apartment}      |
    | PUT/PATCH | panel/investments/flats/{apartment}      |
    | DELETE    | panel/investments/flats/{apartment}      |
    | GET/HEAD  | panel/investments/flats/{apartment}/edit |