1

I am just getting started with Laravel and find the route setup a little confusing. I am trying to create a few pages, that ultimately should have the struture:

domain.com/onboarding
domain.com/onboarding/skip
domain.com/onboarding/skip/anothersubview

etc.

Right now I have:

// Registered and Activated User Routes
Route::group(['middleware' => ['auth', 'activated', 'activity']], function () {

    Route::get('/onboarding', 'UserController@Onboarding')->name('onboarding');
});

Would the solution here (and best practice) be to just add another route inside my Route::group, like:

Route::view('/onboarding/skip', 'onboarding.skip');

Is this the correct way of doing things?

2
  • I did it in few projects in the past, I just placed group inside of group inside of group and nothing was wrong, I don't know if it's bad or good habit but every page worked smoothly and everything was fine Commented Jul 5, 2018 at 13:26
  • If it's static pages then Route::view is probably the best solution. Also best practice is to be explicit with your routes. That way you know what navigates where without any surprises. Commented Jul 5, 2018 at 13:35

3 Answers 3

1

use prefix :

   Route::group(['prefix' => 'onboarding','middleware' => ['auth', 'activated', 'activity']], function () {

        Route::get('/', 'UserController@Onboarding')->name('onboarding');
        Route::get('/skip', 'UserController@OnboardingSkip')->name('onboarding_skip');
        Route::get('/skip/anothersubview', 'UserController@OnboardingSkipSubview')->name('onboarding_skipsubview');

    });

read more here : https://laravel.com/docs/5.6/routing

Sign up to request clarification or add additional context in comments.

2 Comments

But what if I have other routes inside the Route::group that have nothing to do with /onboarding
you need to define separate route , which does not have prefix onboarding
1

The structure I used in a few projects in the past looks like this:

Route::group(['prefix' => 'onboarding'], function(){
    Route::group(['prefix' => 'something'], function(){
        Route::get('/', function(){}); //onboarding/something
        Route::group(['prefix' => 'somethingelse'], function(){
            Route::get('/', function(){}); //onboarding/something/somethingelse
            Route::get('/{id}', function(){}); //onboarding/something/somethingelse/15
        });
    });
});

nesting groups can help you make the easier extendable router because when you realize you need to add some URL in the middle of long structure it would be easier to do it with this concept

Comments

0

You have a web.php file in your routes folder, there you need to add:

Route::get('/subpage', 'controllername@function-name-you-want-to-call');

Hope this helps, if it doesn't let me know

/e: to clarify:

the first part

Route::group(['middleware' => ['auth', 'activated', 'activity']], function () {

is the authentication. Depending on who you want to access this page, you might not need it

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.