I'm facing a weird situation, just look at the following code in a blade file, and the output of it
Blade
{{ url('xero_invoice_authorised') }}</br>
config app url - {{ config('app.url') }}</br>
env app url - {{ env('APP_URL') }}
Output
http://xxxx/xero_invoice_authorised
config app url - https://xxxx/
env app url - https://xxxx/
url() is returning the URL as http: but it should be https:.
The system is inside a docker container.
I have run all commands to clear the cache, view, routes, and even ran optimize command.
Can anyone suggest to me what's wrong with my configuration? or any method to rectify this issue?
I need {{ url('') }} to return the APP_URL in the .env file.
There is no error at all, it is working as expected.
First of all, never use
env()outside theconfigfolder, because when you runphp artisan optimizeorphp artisan config:cache,env()will always returnnull. More info in the documentation. I understand if this is just a test, but have it always in mind.Second,
url()will ALWAYS returnhttpinstead ofhttps. You have to usesecure_url()if you wanthttps. Check the documentation forurl()andsecure_url().Third, just to show you how it works, here is the official source code of
url(), theUrlGeneratoris the one processing thehttp://orhttps://, you can try debugging what it is reading and checking why it is using insecure instead of the other one.