Naming Resource Route Parameters
Route::resource
will create the route parameters for your resource routes based on the "singularized" version of the resource name. You can easily override this on a per resource basis by using the parameters
method. The array passed into the parameters
method should be an associative array of resource names and parameter names:
Route::resource('users', 'AdminUserController')->parameters([
'users' => 'admin_user'
]);
The example above generates the following URIs for the resource's show
route:
Example(1)
Route::resource() method generates the route parameters for all the resource routes automatically, but we can override the route parameters by using the parameters array. The parameters array is an associative array of the resource name and route parameters.
We can override the route parameters by adding the following code in web.php file:
Route::resource('demo', 'demoController', ['parameters' => ['demo' => 'user_demo']]);