Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel auth check for all pages

I have created the Authentication, and its working perfectly. But there is some problem in checking the inner pages. For example,

Route::get('/', array('before' => 'auth' , 'do'=> function(){
return View::make('home.index');
}));

The index page is only visible for logged in users. But whenever I have go to the inner pages, for example example.com/products. The products page can be visible without log in.

like image 837
KKK Avatar asked Dec 06 '12 14:12

KKK


1 Answers

Here is my solution.

/**
 * Groups of routes that needs authentication to access.
 */
Route::group(array('before' => 'auth'), function() 
{
    Route::get('user/logout', array(
        'uses' => 'UserController@doLogout',
    ));

    Route::get('/', function() {
        return Redirect::to('dashboard');
    });

    Route::get('dashboard',  array(
        'uses' => 'DashboardController@showIndex',
    ));

    // More Routes

});

// Here Routes that don't need Auth.
like image 83
Juan Escobar Avatar answered Oct 04 '22 21:10

Juan Escobar