Laravel Resourceful Route Without Prefix

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
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.