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.
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.
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.
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.
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.
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']]);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With