VBtutorials VBtutorials - 1 year ago 106
PHP Question

Restricting routes with auth middleware group in laravel 5.2

I'm trying to prevent people from accessing the

route unless they're authenticated(logged in). I looked at the laravel docs and here's what I thought I was supposed to do to accomplish this.

Route::group(['middleware' => 'auth'], function (){
Route::get('/dashboard', [
'uses' => 'UserController@getDashboard',
'as' => 'dashboard'

Answer Source

You don't need to add that extra middleware in the route. Just use the group and you'll be fine. You can see here: https://laravel.com/docs/5.1/routing#route-groups

Route::group(['middleware' => 'auth'], function () {
    // User needs to be authenticated to enter here.
    Route::get('/', function ()    {
        // Uses Auth Middleware

    Route::get('user/profile', function () {
        // Uses Auth Middleware
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download