Authenticated Routes in Laravel

Written by SarahS

28th April 2020

Once you’ve set up your project with Authentication you will probably then want to add pages which require the user to be logged in.  In the Routes/web.php file you need to add in these routes.

The simplest one for a one page is:

Route::get('/home', 'HomeController@index')->name('home')->middleware('auth');

However, if you are going to need more than one page to be authenticated then it’s best to group them altogether like this:

Route::group(['middleware' => ['auth']], function () { 
    Route::get('/home', 'HomeController@index')->name('home');
    Route::get('contact-us', 'ContactController@getContact');
    Route::post('contact-us', 'ContactController@saveContact');

    Route::resource('email', 'EmailController');
});

This is one of my Laravel posts.  I’m still learning Laravel so the posts are usually pretty basic and are more aimed at keeping track of things that I find useful so that I can come back to them again at a later date.  I hope you find them useful too.  If not, or if you think they are wrong then please leave a comment below.  Thank you.

Faster Laravel Hosting

If this post helped you or if you have any questions please leave me a comment below:

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

You May Also Like…

Setting up SQLite for Laravel

Setting up SQLite for Laravel

Sometimes you may decide you want to use SQLite for your Laravel app instead of a full blown MySQL database. In that...