Laravel 定数の設定

定数を設定したいのでドコに設定ファイルを置くのがベターか調べてみた

作成日:2022-11-30, 更新日:2022-11-30

メモ

「app/const/xxx.php」ってのを作るのが無難っぽい

▼app/const/xxx.php

<?php

namespace App\Consts;

class xxxx {
  public const VAL_HOGE = 1;
  public const VAL_FOO  = 2;
  public const LABEL_VAL = [
    self::VAL_HOGE => 'ほげ',
    self::VAL_FOO  => 'ふー',
  ];
}

▼呼出し方法

$ label_many = App\Consts\xxxx::LABEL_VAL