How To Create Naming Resource Routes In Laravel Framework

admin_img Posted By Bajarangi soft , Posted On 17-09-2020

Laravel resource controllers provide the CRUD routes to the controller in a single line of code. A resource controller is used to create a controller that handles all the http requests stored by your application. The resource() is a static function like get() method that gives access to multiple routes that we can use in a controller.

How To Create Naming Resource Routes In Laravel Framework

Naming Resource Routes

By default, all resource controller actions have a route name; however, you can override these names by passing a names array with your options:
 

Route::resource('photos', 'PhotoController')->names([
'create' => 'photos.build'
]);


All the methods of the controller have a default route name, but Laravel allows you to override the route names by passing name array. Name array contains the name of the routes that you want to specify of your choice.

For Example(1)

  • We can add the below code in web.php file to name the resource routes.

    Route::resource('demo', 'demoController',['names' => ['create' =>'demo.build']]);

Related Post