あじちゃんの備忘録。

〜ここはメモ帳です

env("PARAMETER") といった形の .env で定義した値が読み込めなく(Nullに)なる

2018/07/02

ローカルログイン画面からログインできない件

起こったこと: env("PARAMETER") といった形の .env で定義した値が読み込めなく(Nullに)なる事象が発生していた。

原因1:configキャッシュの作り直しをするため php artisan config:cache コマンドを実行し、キャッシュが固定されたため。

原因2:5.2以降の仕様で、キャッシュがある時は、 config/*.php 以外の場所で使われる env() は無効化される。(NULLになる)

解決方法:以下のコマンドを実行

# キャッシュファイルの場所まで移動
$ pwd
~projectdir/bootstrap/cache

# configのキャッシュファイルを削除
$ ls -l
-rw-r--r--  1 user_name  46682944  16560  6 28 16:43 config.php
$ rm -f config.php

Upgrading To 5.2.0 From 5.1 > Configuration

Caching And Env
If you are using the config:cache command during deployment, you must make sure that you are only calling the env function from within your configuration files, and not from anywhere else in your application.

If you are calling env from within your application, it is strongly recommended you add proper configuration values to your configuration files and call env from that location instead, allowing you to convert your env calls to config calls.