Laravel same route, different controller

后端 未结 4 1279
执念已碎
执念已碎 2020-12-19 12:16

I would like to have general home page and a different homepage for logged-in users
I search a lot on google but I can\'t find what to put in my if statement

I t

4条回答
  •  情书的邮戳
    2020-12-19 12:40

    // routes.php
    Route::get('/', 'homecontroller@index');
    
    
    
    // homecontroller.php
    class homecontroller extends BaseController
    {
        public function index()
        {
            if (!Auth:: check()) {
                return $this->indexForGuestUser();
            } else {
                return $this->indexForLoggedUser();
            }
        }
    
        private function indexForLoggedUser()
        {
            // do whatever you want
        }
    
        private function indexForGuestUser()
        {
            // do whatever you want
        }
    
    }
    

提交回复
热议问题