Set Headers in Laravel

Set Headers in Laravel: There are many ways you can set headers in Laravel. You can set header directly in view or you can use before filter to bind headers in All views. Here in this tutorial we are going to explain how you can set headers in Laravel.

How to Set Headers in Laravel Example

You can add the headers in your view file directly, here in an example of setting headers in view file –

Set Headers in Laravel Example:

// Outputting a PDF
header('Content-Type: application/pdf');

// It will be called my_download.pdf
header('Content-Disposition: attachment; filename="my_download.pdf"');

// The PDF source is in original.pdf

You can set other headers on the same way in Laravel.

Add Comment

📖 Read More