laravellaravel-5.8

How to call .env {{ env('APP_NAME} }} to laravel blade template?


I tried to call APP_NAME from .env Laravel to Blade Template, but it always returned this code
<?php echo e(env('APP_NAME')); ?>

Master Blade master.blade.php

<title>@yield('project_title')</title>

Body Blade body.blade.php

@extends('master')

@section('project_title', "{{ env('APP_NAME') }}")

I was tried to use this :

php artisan config:clear
php artisan cache:clear
composer dump-autoload
php artisan view:clear
php artisan route:clear

but still give me the same return.


Solution

  • In fact you should never use env helper directly in your application. All env should be put into config file and you should use config instead to avoid problems when config files are cached.

    APP_NAME env is put into config file by default (see https://github.com/laravel/laravel/blob/master/config/app.php#L16 ) so in your Blade file you should use:

    @section('project_title', config('app.name'))