Support the ongoing development of Laravel.io →
Laravel Requests

Laravel request() helper won't work when app is optimized.

strtolower(request()->header('Request-From')) == "portal" ? "auth:sanctum" : "api.auth";

I have a logic to check which middleware to use depending on a header Request-From value. This works perfectly when the app is not optimized. But when i run php artisan optimize, the ternary operator returns false giving me api:auth. Again when i run php artisan optimize:clear i have auth:sanctum.

PS: The request header was available when checked with telescope

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.