vendredi 25 mai 2018

Change Route::filter to BeforeMiddleware Laravel 5.0

I'm working on a upgrade from Laravel 4.2 to 5.0 and on the proyect I got a lot of Route::filter, and i read there's a way to change those ones to Middleware, but i don't understand at all how do it.

This is one of my Route::filter:

Route::filter('auth.basic', function(){
    return Auth::basic();
});

And here is my BeforeMiddleware:

<?php namespace App\Http\Middleware;

use Closure;

class BeforeMiddleware {

/**
 * Handle an incoming request.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Closure  $next
 * @return mixed
 */
public function handle($request, Closure $next)
{

    if($request->filter('auth')){
        //here do something
    }

    if($request->filter('api.auth')){
        //here do something
    }

    if($request->filter('auth.basic')){
        //here do something
    }

    if($request->filter('sales.auth')){
        //here do something
    }

    if($request->filter('distributer.auth')){
        //here do something
    }

    if($request->filter('log.request')){
        //here do something
    }

    if($request->filter('tech.auth')){
        //here do something
    }

    return $next($request);
  }

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire