Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get custom header from HTTP response in Laravel 5?

I'm trying to access a custom header from the Request in Laravel. The header name is "accessing_from". Listing all the headers in Laravel, gives me only the "standard ones", but the one that I've set isn't present in the list. Checking in the browser network tab I can see that the header gets sent. So I'm wondering how to access it from within Laravel.

I'm using Angular2 to make the request with the default http service.

The Laravel's $response->header() dump:

enter image description here

The web inspector's log:

enter image description here Thanks to anyone!

like image 679
Caius Avatar asked Dec 13 '16 10:12

Caius


People also ask

How do I get headers in laravel?

Laravel provides many details in Illuminate\Http\Request class object. You can simply get headers details using headers() method. This will return all headers in array.

How can you retrieve the full URL for the incoming request in laravel?

The “path” method is used to retrieve the requested URI. The is method is used to retrieve the requested URI which matches the particular pattern specified in the argument of the method. To get the full URL, we can use the url method.


1 Answers

Are you talking about get parameter or something? If so, use:

request()->accessing_from;

For header you should use:

request()->header('accessing_from');

The working solution for this was the answer (the last one) of daver here: Laravel get request header

like image 69
Alexey Mezenin Avatar answered Sep 26 '22 17:09

Alexey Mezenin