0

I have a controller with several methods and I need to add a specific authorization check. If authorization failed then redirect login page. So for this reason i have created one private function and this function call in constructor.

class AdminController extends Controller
{
    public function __construct()
    {
        $this->middleware('web');
        $this->isLogin();
    }

    private function isLogin()
    {
        if (!empty(Auth::user())) {
            echo "Hello";
        } else {
            echo "Fasd";
            return Redirect::to('/login');
        }
    }
}

If auth is not found is does not redirect to login. What i write extra code for this?

Andrew
  • 1,858
  • 13
  • 15
sandip kakade
  • 1,346
  • 5
  • 23
  • 49

1 Answers1

4

Doing login page redirect use redirect::route into login page alias name routes.php.

public function isLogin()
{
    if (!empty(Auth::user())) {
        echo "Hello";
    } else {
        echo "Fasd";
        return Redirect::route('login');
    }
}