ペチパーノート

WEB開発系Tipsブログです。

Laravel 定数を使うのは.envだけではダメ

.envにも書いて

API_URL=https://example.jp/list

config/xxx.phpにも書く(configでenvから取得する)

<?php

return [
    'api_url' => env('API_URL'),
];

使いたいところでconfig()で取得する

public function __construct()
{
    $this->api_url = config('api_url');
    $this->http_method = 'post';
    $this->client = new Client();
…
}