lundi 26 juin 2017

Laravel Middleware changing header before passing to controller

I'm trying to change the header of my request before passing it to the controller using a middleware but it seems $next($request) executes the code in my controller. Is there a way to change the header then send the updated request to my controller?

My middleware:

class JWTAuthenticator
{

public function handle($request, Closure $next)
{
    //it runs here
    $response = $next($request);

    //it runs this part after executing the controller  
    $response->header('Authorization','Bearer '.$my_new_token);
    return $response;
}

This is how the middleware is assigned to my route:

Route::get('/{user}', 'v1\UserController@find')->middleware('jwt_auth');



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire