You shouldn't use env in either of those places. Only use env() in your config files and in other places use config() instead and read a config value. That way you can cache your config.
Oct 16, 2019
11
Level 27
Using env
What is the difference between the two:
This one shows the right path:
home_slides.blade.php
<td><img src="{{ env('STORAGE_URL').$item->image }}"></td>
This one does not shows the env('STORAGE_URL') path:
edit_home_slides.blade.php
<td><img src="{{ env('STORAGE_URL').$list->image }}"></td>
.env
STORAGE_URL=http://localhost/aws_admin_test/storage/app/
I wonder what's wrong with edit_home_slides.blade.php?
Am I allowed to use env in views ? How about in controller?
Level 73
You should always read from the config, and the config always reads from the .env file
env('APP_URL', 'http://localhost'),
This means, read what is stored in .env file for the key APP_URL if there is nothing set there, then use http://localhost.
1 like
Please or to participate in this conversation.