2015-01-30 9 views
0

나는이 두 경로를가집니다. 첫 번째는 성공적인 로그인 후에 '/ add'로 리디렉션되지만 Auth :: check에는 항상 실패하고 'not logged'라고 대답합니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?로그인 후 리디렉션 laravel

Route::post('/login', function() { 
$log = Input::all();  
if (Auth::attempt(['user_name' => $log['username_log'], 'password' => $log['pass_log']])) {  
    return Redirect::intended('/add'); 
} else { 
    return View::make('index', ['log_error' => '<p class="log_error">Incorrect username or password. Please, try again!</p>']); 
} 

});

Route::get('/add', function() { 
if (Auth::check()) { 
    echo 'logged'; 
} else { 
    echo 'not logged'; 
} 

});

답변

0

필터를 사용하면 로그인했는지 여부를 확인하는 필터를 사용하면됩니다. 원하는 경우 계속 진행할 수 있으며 그렇지 않은 경우 로그인 양식으로 리디렉션 할 수 있습니다.

여기에 설명 자세한 내용이있다 :

Route::group(['before' => 'auth', 'prefix' => 'app'], function() { 
    Route::intended('/app'); 
}); 

이것은 또한 당신이 이해를 얻을 도움이 될 것입니다

그러나이처럼 사용하십시오 있도록 "인증"필터는,이 기본적으로 http://laravel.com/docs/4.2/routing#route-filters 그것의 : http://laravel.com/docs/4.2/security#authenticating-users