Home » Php » Get Header Authorization key in laravel controller?

Get Header Authorization key in laravel controller?

Posted by: admin November 30, 2017 Leave a comment


Trying to get the header authorization key in controller for making an API. Request is making from fiddler.

$headers = apache_request_headers();

And the $header contains an array.

    [User-Agent] => Fiddler
    [Host] => localhost:8000
    [Content-Length] => 102
    [Authorization] => TestKey

If am trying like this to fetch the Authorization , its throwing error.


Error :

Undefined index: Authorization

Tried many ways to get the authorization, but not working anything. Is there any way to fetch this?


To get headers from the request you should use the Request class

public function yourControllerFunction(\Illuminate\Http\Request $request)
    $header = $request->header('Authorization');

    // do some stuff