2

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?

shaedrich
  • 5,457
  • 3
  • 26
  • 42
natsukiss
  • 31
  • 5
  • its correct.if you dd($request->all()) then you get these default params. – John Lobo Jun 02 '21 at 07:22
  • parameters will Override the route parameter names. – John Lobo Jun 02 '21 at 07:23
  • As far as I can see, you're trying to override route segments or actions but not route parameters. Route parameters are those in curly braces. – shaedrich Jun 02 '21 at 07:38
  • @shaedrich I know what you mean, but my goal is to add a parameter to the index function, for example, so that calling it looks like index/{parameter}. I found solution on laracast: https://laracasts.com/discuss/channels/laravel/routeresource-parameters but it's not working – natsukiss Jun 02 '21 at 07:43
  • So which route doesn't have the `{flat}` parameter? Did you forget to mention it in your picture? – shaedrich Jun 02 '21 at 07:45
  • @shaedrich now I don't understand what you're trying to tell me. I would like to add an extra parameter for the index function in resource routing. That's all. The way I want to add an additional parameter is not visible in the list at all, which is visible in the picture I sent – natsukiss Jun 02 '21 at 07:49
  • See my answer below ;-) – shaedrich Jun 02 '21 at 07:59

1 Answers1

1

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 |
shaedrich
  • 5,457
  • 3
  • 26
  • 42
  • So i can't add additional parameter into resource routing like this: https://laracasts.com/discuss/channels/laravel/routeresource-parameters ? – natsukiss Jun 02 '21 at 08:04
  • Adding additional parameters and overriding existing one's are two very different animals – so as far as I know, no. – shaedrich Jun 02 '21 at 08:06