close
source:http://stackoverflow.com/questions/19032957/laravel-4-add-a-filter-to-a-route-a-pass-it-a-controller
I want do a backend website, when user come the index page, The page must have auth function or filter.
===========================================
You should pass the controller function with uses
key, So replace,
Route::get('/', array('before'=>'auth','HomeController@index'));
And there should be a route for login to process the auth
filter like this.
Route::get('login',function()
{
if(Auth::user()){
returnRedirect::to('/');
}
returnView::make('login');
});
good idea I like.
or
Wanted to add another solution to your problem.
You can also use this, which in my opinion feels more readable.
Route::get('/','HomeController@index')->before('auth');
You only need to use "as" and "uses" if you're in need of named routes, eg. for a Form route.
全站熱搜