This content originally appeared on DEV Community and was authored by Ibrar Hussain
When you create a controller, Laravel does provide you with the route resource which provides out of the box CRUD operation routes. You can check these named routes by the following command:
php artisan route:list
By default, following is the list of the photos
controller CRUD operation routes:
Verb | URI | Action | Route Name |
---|---|---|---|
GET | /photos | index | photos.index |
GET | /photos/create | index | photos.index |
POST | /photos | index | photos.index |
GET | /photos/{photo} | index | photos.index |
GET | /photos/{photo}/edit | index | photos.index |
PUT/PATCH | /photos | index | photos.index |
DELETE | /photos | index | photos.index |
Sometimes, we may want to use only few of the routes from the CRUD operation and let's say we want to use only index
, create
, store
, edit
and update
, we can customise it like the following:
Route::resource('photos', 'PhotoController')->only('index', 'create', 'store', 'edit', 'update');
We can also specify the as option to define a prefix for every route name.
Route::resource('photos', 'PhotoController', [
'as' => 'foo'
]);
Similarly, you can also provide a custom name for each controller methods like the following:
Route::resource('photos', 'PhotoController', [
'names' => [
'index' => 'foo',
'store' => 'foo.new',
// etc...
]
]);
This content originally appeared on DEV Community and was authored by Ibrar Hussain

Ibrar Hussain | Sciencx (2022-02-19T04:29:08+00:00) Customise Laravel Route for Resource Controller. Retrieved from https://www.scien.cx/2022/02/19/customise-laravel-route-for-resource-controller/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.