New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method [beforeFilter] does not exist. Laravel 5.2 #11640

Closed
umairali opened this Issue Dec 31, 2015 · 8 comments

Comments

Projects
None yet
6 participants
@umairali
Copy link

umairali commented Dec 31, 2015

i m using beforeFilter to redirect user to login page when session expire but before filter not working in laravel 5.2

public function __construct()
{
      $this->beforeFilter(function()
      {
           return Redirect(URL('/') . "/login");
      });
}

and this error message throw

capture

@crynobone

This comment has been minimized.

Copy link
Contributor

crynobone commented Dec 31, 2015

Deprecated in 5.1 and removed in 5.2

@mikerockett

This comment has been minimized.

Copy link

mikerockett commented Dec 31, 2015

@umairali - I suggest you read through the documentation for 5.2 - lots of changes, even in 5.1, which now uses Middleware, and not Filters.

@KaneCohen

This comment has been minimized.

Copy link
Contributor

KaneCohen commented Dec 31, 2015

@umairali here you can find descriptions of changes between versions: https://laravel.com/docs/5.2/upgrade as guys above mentioned - a lot has changed.

@umairali

This comment has been minimized.

Copy link

umairali commented Dec 31, 2015

ok please give me any suggestion for redirection in controller constructor

@umairali

This comment has been minimized.

Copy link

umairali commented Dec 31, 2015

_Solution_

Change

public function __construct()
{
$this->beforeFilter(function()
{
       return Redirect(URL('/') . "/login");
});
}

To

public function __construct()
{
      Redirect('login')->send();
}
@GrahamCampbell

This comment has been minimized.

Copy link
Member

GrahamCampbell commented Dec 31, 2015

That's not a correct solution.

@GrahamCampbell

This comment has been minimized.

Copy link
Member

GrahamCampbell commented Dec 31, 2015

You should never send a response directly in the code, ever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment