Search code examples
laraveleloquentlaravel-bladelaravel-8laravel-middleware

Laravel 11 Storage URL not triggering Middleware


I have a storage url that can be opened and it looks like this

<a href="{{ Storage::url('invoices/'. $invoice->invoice_number . '.pdf')  }}?is_opened={{ $token }}" class="f-fallback button button--blue" target="_blank">View Invoice</a>

The intended action should be a custom middleware running when this link is opened. Whenever i click the button, the middleware is ignored. I have the middleware set up correctly as it runs on every single page without any issues.

Question: Does middleware not affect storage URLs?


Solution

  • Files placed in the storage/ folder are called directly so middleware won't be called when you access them.

    If you want to use middleware while downloading/accessing something from the storage/ folder, you can make a separate route and then apply middleware to it.