我有一個奇怪的重定向不工作,如果我把重定向的行動外。例如:Laravel返回重定向::不工作以外的行動
下面代碼工作
Route::get('/', '[email protected]');
public function index()
{
if (Auth::check())
{
$this->user_id = Auth::id();
}
else
{
return Redirect::to('/');
}
// code after check
}
但如果我把它拿出來像下面,重定向將不起作用。它根本不重定向。
Route::get('/', '[email protected]');
public function index()
{
$this->authorize();
// code after check
}
private function authorize()
{
if (Auth::check())
{
$this->user_id = Auth::id();
}
else
{
return Redirect::to('/');
}
}
現在,如果我必須在每個動作中繼續使用if語句,那將是麻煩的。相反,我需要調用$ this-> authorize();
任何想法爲什麼它不會工作?
嘗試過,但仍然不能正常工作 – jmjap 2014-10-12 06:07:10
Uppss,它實際上是與您的解決方案一起工作。謝謝 – jmjap 2014-10-12 06:15:15