Laravel Resourceful Route Without Prefix

General

The resource controller contain a method for each of the available resource operations.

For example:

Route::resource('photos', 'PhotoController');

is handle by the verbs in the controller. such as

/photos
/photos/create
/photos/{photo}
/photos/{photo}/edit
...

If you want the resource without the name, you can do

Route::resource('/', 'PhotoController');

but the parameters will not work properly since the route will become

/
/create
/{}
/{}/edit

in order to "fix" that, you can do

Route::resource('/', 'PhotoController')->parameters([
  '' => 'photo',
]);

so the route now is

/
/create
/{photo}
/{photo}/edit

Next | Previous

Other posts