1 year ago

How to add Bearer Token in Request Header Using Laravel Controller or Middleware

Posted 1 year ago by Majeed

I'm working on Laravel API Authentication. for every request I'm added the Bearer Token in request Header. But I want to do this from my Backend controller or middleware. i'm tried this way But it's not working.

My Middleware.

 public function handle($request, Closure $next)
        $request->header('Authorization',"Bearer ".$request->bearerToken());

        return $next($request);

My Kernal File.

protected $middlewareGroups = [

        'Header'  =>[

and my Route

Route::group(['middleware' => ['auth:api','Header']], function(){
Route::post('details', 'API\[email protected]');
Route::get('test','API\[email protected]');

Please sign in or create an account to participate in this conversation.