There is a background base class controller here, which determines whether the user is logged in, and then jumps to the specified method if not logged in, but the sentence inside "return Redirect: :to('admin\login@login')" doesn't work. The page always jumps to the home page after logging in. Instead of going to the login page.
Who can explain it to me and point out the error.
淡淡烟草味2017-05-16 16:56:26
It really doesn’t work. At that time, I encountered the same problem as the original poster. Since it was urgent at the time, I didn’t go into details. Personally, I feel that since it is a parent class, it seems that Redirect cannot jump.
Follow.
Modified on May 30, 2016. After looking at it, my solution at that time was to use Laravel’s built-in auth middleware
public function __construct(){
$this->checkLogin();
}
/**
* check login
*/
protected function checkLogin(){
//子类需要判断登录,则使用auth中间件
if($this->boolNeedLogin){
$this->middleware('auth');
}
}
世界只因有你2017-05-16 16:56:26
You can directly use redirect
Jump
return redirect('/home');//跳转到domain/home
return redirect('/articles/1');//跳转到domain/articles/1
巴扎黑2017-05-16 16:56:26
It is recommended that LZ try to change return to echo. For constructors, return does not receive objects and generally has no effect.
伊谢尔伦2017-05-16 16:56:26
Redirect::to('login')->send();
That’s it.
Here is a detailed explanation.
http://stackoverflow.com/questions/27568147/laravel-constructor-redirect-is-not-working