Display file data . env in Blade

Asked

Viewed 193 times

0

I would like to read some data from the archive .env on the page .blade.php, but some do not work, for example, I am using the following way:

apkey: {{env('PUSHER_APP_KEY')}} #ler chave PUSHER_APP_KEY                   
key: {{config('database.base')}} #ler chave base do arquivo app/database.php
broadcasting:{{config('broadcasting.key')}} #ler chave key do arquivo app/broadcasting.php

Where my file .env the following values are configured

PUSHER_APP_ID = minhaid
PUSHER_APP_KEY = minhachave
PUSHER_APP_SECRET = minhasenha
PUSHER_APP_CLUSTER = us2

An excerpt from my archive broadcasting.php is like this:

return [    
  'default' => env('BROADCAST_DRIVER', 'null'),
  'key'  => env('PUSHER_APP_KEY'),

An excerpt from my archive database.php is like this:

 return [
   'base' => env('DB_HOST', '127.0.0.1'), 
      /* ... */

Just the return of database.php works in the above example, I cannot read the data from broadcast. How do I read from the file .env?

1 answer

0

Just put the name of the key that is in the file .env, example:

APP_ENV=local
APP_KEY=base64:M2eN0OPMVR/CDoUSlI+bZW1sgqgmkqC/l7R8omQx8Dc=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=root
DB_PASSWORD=senha

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_KEY=
PUSHER_SECRET=

How to use?

+----------------------------------+---------------------------------------+
| Comando                          | Saída                                 |
+----------------------------------+---------------------------------------+
| env('APP_ENV');                  | local                                 |
+----------------------------------+---------------------------------------+
| env('DB_CONNECTION');            | mysql                                 |
+----------------------------------+---------------------------------------+
| env('BROADCAST_DRIVER');         | log                                   |
+----------------------------------+---------------------------------------+

and so on.

  • Yes. The keys were already

  • @adventistaam is how it does and works

  • Yeah. They didn’t work

  • It worked when I changed PUSHER_APP_ID for PUSHER_ID

  • @adventistaam has something wrong in your project

Browser other questions tagged

You are not signed in. Login or sign up in order to post.