0

I use Laravel 8. How to add except rule in Route::resources? I want to achieve something like the below:

Route::resources(
  [
     'designations' => 'DesignationController',
     'locations' => 'locationController'
  ],
  [
     'except' => ['edit']
  ]
);

I noticed that the above is possible with Route::apiResources (as explained here: how to use apiReources method with `only`?) but not with Route::resources.

Edit

It was an issue with my IDE, where Route::resources was referring to a different version of resources function. The above route definition is correct.

Aditya Sharma
  • 1,641
  • 2
  • 8
  • 10
  • how are you determining that it does not work that way?... you are missing a closing `]` in your example btw – lagbox Sep 12 '20 at 13:57
  • @lagbox Thanks for pointing out the typo. I edited to correct it. But that's not the real issue. – Aditya Sharma Sep 12 '20 at 14:09
  • @lagbox Unlike Route::apiResources, Route::resources function accepts only one parameter. Is there any alternate approach to achieve what I'm looking for, i.e., define same "except" route(s) for all the resource routes (there are many more resources in the list)? – Aditya Sharma Sep 12 '20 at 14:59
  • it does not only take 1 paremeter, it takes 2 ... `public function resources(array $resources, array $options = [])` which is the same exact signature as `apiResources` – lagbox Sep 12 '20 at 14:59
  • @lagbox Thanks for your comment. You are right. The above route definition does work. It was actually issue with my IDE, which was referring to a different version of `resources` function. – Aditya Sharma Sep 12 '20 at 15:48

1 Answers1

2

You have to write your route like this -

Route::resource('photos', PhotoController::class)->except([
    'create', 'store', 'update', 'destroy'
]);

or you can also write like this -

 Route::resource('photos', PhotoController::class)->only([
    'index', 'show'
]);
Jaynil Savani
  • 310
  • 2
  • 9