Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.3 Resource routes names

I upgraded my Laravel 5.2 application to Laravel 5.3. I have a lot of Resource routes like:

Route::resource('web/products', 'Web\ProductController', ['except' => ['show']]);
Route::resource('web/promos',   'Web\PromoController',   ['except' => ['show']]);

The route names generated for them until Laravel 5.2 were:

web.products.index
web.products.create
web.products.store
web.products.edit
web.products.update
web.products.edit

I used the route() helper to print all the routes by its name. The problem is that now Laravel 5.3 is generating my routes with this names:

products.index
products.create
products.store
products.edit
products.update
products.edit

I need them to be fully namespaced.

like image 213
Alan Avatar asked Oct 04 '16 17:10

Alan


People also ask

How do I name a resource route in Laravel?

x | Laravel 5. x). There are two ways you can modify the route names generated by a resource controller: Supply a names array as part of the third parameter $options array, with each key being the resource controller method (index, store, edit, etc.), and the value being the name you want to give the route.

What is resource route Laravel?

Route::resource: The Route::resource method is a RESTful Controller that generates all the basic routes required for an application and can be easily handled using the controller class.

Where is the routing file located in Laravel?

All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by your application's App\Providers\RouteServiceProvider . The routes/web.php file defines routes that are for your web interface.

What is use of controller in Laravel?

Controllers can group related request handling logic into a single class. For example, a UserController class might handle all incoming requests related to users, including showing, creating, updating, and deleting users. By default, controllers are stored in the app/Http/Controllers directory.


1 Answers

You can give "as" parameter in group directive for giving all group routes a prefix.

Route::group(['as'=>'web.'], function() {
    Route::resource('web/products', 'Web\ProductController', ['except' => ['show']]);
    Route::resource('web/promos',   'Web\PromoController',   ['except' => ['show']]);
});

Also you can specify prefix for url

Route::group(['as'=>'web.','prefix'=>'web'], function() {
    Route::resource('products', 'Web\ProductController', ['except' => ['show']]);
    Route::resource('promos',   'Web\PromoController',   ['except' => ['show']]);
});
like image 152
Aykut CAN Avatar answered Sep 29 '22 07:09

Aykut CAN