laravel5 jumps to the specified method
某草草
某草草 2017-05-16 16:54:26
0
6
767


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.

某草草
某草草

reply all(6)
巴扎黑

Use:

redirect()->action('YourController@method');
淡淡烟草味

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');
        }
    }
世界只因有你

You can directly use redirectJump

return redirect('/home');//跳转到domain/home

return redirect('/articles/1');//跳转到domain/articles/1
PHPzhong

route("admin\loginController@index")

巴扎黑

It is recommended that LZ try to change return to echo. For constructors, return does not receive objects and generally has no effect.

伊谢尔伦
Redirect::to('login')->send();

That’s it.
Here is a detailed explanation.
http://stackoverflow.com/questions/27568147/laravel-constructor-redirect-is-not-working

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template