CharliePrynn
CharliePrynn

Reputation: 3082

Laravel 5 route groups `prefix and `as` and resource controllers

I'm using Laravel's route groups to try and stop duplication within my Routes file.

I have one main group, frontend. This has the namespace Frontend and as frontend.

Nested within that group, is another group. This group has the prefix account which appends /account/ to each route. It also has as account..

The routes inside the nested group, I'd expect to be:

  1. frontend.account.home
  2. frontend.account.order.show
  3. frontend.account.order.index

Instead I get:

  1. frontend.account.home
  2. frontend.account.account.order.index
  3. frontend.account.account.order.show

Code:

Route::group(['as' => 'frontend.', 'namespace' => 'Frontend'], function () {
    Route::group(['prefix' => 'account', 'as' => 'account.', 'namespace' => 'Account'], function () {
        Route::get('home', [
            'as'   => 'home',
            'uses' => 'Home\Controller@get'
        ]);

        Route::resource('order', 'Order\Controller', ['except' => [
            'create',
            'store',
            'update',
            'destroy',
            'edit',
        ]]);
    });
});

Upvotes: 0

Views: 1216

Answers (1)

shempignon
shempignon

Reputation: 562

Since your excepting almost every routes from the Route::resource method, why not create 2 single routes for index and show like so:

// in your routes file, within your nested group :
Route::get('order', ['as' => 'order.index', 'uses' => 'Order\Controller@index' ]);
Route::get('order/{id}', ['as' => 'order.show', 'uses' => 'Order\Controller@show' ]);

Upvotes: 1

Related Questions