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.



   
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 hmc0316 的頭像
    hmc0316

    hmc0316的部落格

    hmc0316 發表在 痞客邦 留言(0) 人氣()