Mahdi
Mahdi

Reputation: 115

Best way to write Group routes with prefix in laravel 5.5

What is the best and correct way to write the following routing:

Route::group(['middleware' => ['web']],function (){
    Route::prefix('user')->group(function () {
        //this address shows the login page
        Route::any('login', 'User@login_page');
        //others address that control the login action
        Route::prefix('login')->group(function (){
            Route::get('google', 'User@check_user_login_with_google');
            Route::post('form', 'User@check_user_login_with_form');
            Route::get('google-url', 'User@redirect_to_google_url');
        });
        //these address control the registration actions
        Route::any('register','User@register');
        Route::any('register/check','User@check_user_registration');
    });
});

Upvotes: 1

Views: 644

Answers (2)

Anil Kumar Sahu
Anil Kumar Sahu

Reputation: 577

You can use all these in a separate associated array and assign this array to the group here is how to do that .

Route::group(['prefix' => 'user', 'as' => 'user.', 'middleware' => ['web']], function() {
  Route::any('login', 'User@login_page');
  ...
})

Hope this may help you

Upvotes: 1

Jason Houle
Jason Houle

Reputation: 320

You can do it all in one shot:

Route::group(['prefix' => 'user', 'as' => 'user.', 'middleware' => ['web']], function() {
  Route::any('login', 'User@login_page');
  ...
})

Upvotes: 2

Related Questions