Wednesday, March 15, 2017

Best way to use middleware Auth in Laravel to redirect

So I'm upgrading a project from Laravel 5.0 to 5.4 and I've just stumble across the method now depreciated beforeFilter which was used this way :

function __construct() {
    $this->beforeFilter('auth', array('only'=>array('showDashboard')));
}

Which basically say (from my understanding) if you'r not logged in yet you can still be redirect to showDashBoard method.

So I'm trying to do something similar.

I've tried $this->middleware('auth', ['except' => ['showDashboard']]); but without success.

I tough of extracting the middleware from the construct and putting it directly in the routes but this not seems to be a clean solution for me.



via Baldráni

Advertisement