jeudi 31 janvier 2019

How to Run Laravel Route Constrains Before Middleware?

I have route something like this /permissions/{uuid} And I have route constrain and middleware.

Constraint Rule: Add in route service provider for all routes it will apply.

Route::pattern('uuid', '[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}');

Middleware Rule:

public function handle($request, Closure $next)
{
    $uuid = $request->route('uuid');

    // Check the uuid in DB and throw an exception

    return $next($request);
}

But the problem here was the middleware was running first. I just want to avoid db call if uuid was not a proper format. Can we run constrain rule first.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire