search

Home  >  Q&A  >  body text

laravel5 jumps to the specified method


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.

某草草某草草2757 days ago759

reply all(6)I'll reply

  • 巴扎黑

    巴扎黑2017-05-16 16:56:26

    Use:

    redirect()->action('YourController@method');

    reply
    0
  • 淡淡烟草味

    淡淡烟草味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');
            }
        }

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-16 16:56:26

    You can directly use redirectJump

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

    reply
    0
  • PHPz

    PHPz2017-05-16 16:56:26

    route("admin\loginController@index")

    reply
    0
  • 巴扎黑

    巴扎黑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.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦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

    reply
    0
  • Cancelreply