Hi ?I am just learning to use Laravel framework and having trouble understanding how to use the values stored in the .env
file. I have created a template application using artisan
and it works.
In the default welcome blade is the code
<div class="title m-b-md">
Laravel <--/*this text needs to change */
</div>
In the file .env
is the lines:
APP_NAME=SomeAppName
APP_ENV=local
APP_KEY=base64:zUm/qFNKTV4gRw6bFcIdOfm5rTzrS8JP1bj2KIz8Rl4=
APP_DEBUG=true
APP_URL=http://localhost
How do i reference the .env
file so that the welcome page shows the value of APP_NAME
("SomeAppName") instead of "Laravel"?
p.s have tried {{ getenv('APP_NAME') }}
and {{ config('app.name', 'SomeAppName') }}
but former gives blank and latter still prints out "Laravel"
You can set default values for environment variables using a . env file, which Compose automatically looks for in project directory (parent folder of your Compose file). Values set in the shell environment override those set in the . env file.
It seems both of @stan & @yash above answers are partially correct.
Please Follow below links:
According to above what you need to do is as below
<div class="title m-b-md">
{{ env('APP_NAME') }}
</div>
Then from console you need to clear cache.
php artisan config:clear
php artisan cache:clear
composer dump-autoload
This should work for you.
<div class="title m-b-md">
{{ env('APP_NAME') }}
</div>
If your running local environment server. Firstly you restart your local environment server and try this.
And if you enabled config cache than run the commands below
php artisan config:clear
php artisan cache:clear
In Blade you could do something like:
{{ env('APP_URL')
In a controller or PHP Class:
env('APP_URL')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With