Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Dev0ps's avatar

How to add Headers in laravel request

for adding security i want to add few headers

recently i added a header in ngnix config file request works but all AJAX REQUEST GAVE 419 ERROR so I remove it from ngnix config file.

is there any way to add request header in laravel directly

0 likes
6 replies
shez1983's avatar

not sure at what point you want to add headers? normally if you are using ajax then you would use the JS to add the headers and in laravel you could use a middleware to check if those exist.

Dev0ps's avatar

guys i am talking about

add_header X-Frame-Options SAMEORIGIN;

types of header

shez1983's avatar

then they could be added via nginx/apache directives..

Cronix's avatar

I add them all to the nginx config for the site.

add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";

etc. Never had a problem with laravel not liking them. Maybe you forgot the quotes around the value?

Please or to participate in this conversation.