Laravel 設定ファイル

.env

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:~
APP_DEBUG=true
APP_URL=http://localhost

DB_CONNECTION=mysql コネクション名(他から参照する際に使用)
DB_HOST=localhost dockerコンテナ名、サーバ名等
DB_PORT=3306
DB_DATABASE=DB名
DB_USERNAME=DBユーザ名
DB_PASSWORD=DBパスワード

APP_ENV

実行環境
シーディングファイル等で利用する

if (app()->environment(['local', 'staging'])) {
 〜
}

database.php

※config\database.php
use Illuminate\Support\Str;

return [

 'default' => env('DB_CONNECTION', 'mysql'),

 

接続設定

 'connections' => [

  'sqlite' => [
   ~
  ],

  .env等から参照されるコネクション名
  'mysql' => [
   'driver' => 'mysql',
   'url' => env('DATABASE_URL'),
   'host' => env('DB_HOST', '127.0.0.1'),
   'port' => env('DB_PORT', '3306'),
   'database' => env('DB_DATABASE', 'forge'),
   'username' => env('DB_USERNAME', 'forge'),
   'password' => env('DB_PASSWORD', ''),
   'unix_socket' => env('DB_SOCKET', ''),
   'charset' => 'utf8mb4',
   'collation' => 'utf8mb4_unicode_ci',
   'prefix' => '',
   'prefix_indexes' => true,
   'strict' => true,
   'engine' => null,
   'options' => extension_loaded('pdo_mysql') ? array_filter([
    PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
   ]) : [],
  ],

  'pgsql' => [
   ~
  ],

  'sqlsrv' => [
   ~
  ],

 

redis設定

  'redis' => [
 
   'client' => 'predis',
 
   'default' => [
    'host' => env('REDIS_HOST', '127.0.0.1'),
    'password' => env('REDIS_PASSWORD', null),
    'port' => env('REDIS_PORT', 6379),
    'database' => env('REDIS_DB', 0),
   ],

   'broadcasting' => [
    'host' => env('REDIS_HOST', '127.0.0.1'),
    'password' => env('REDIS_PASSWORD', null),
    'port' => env('REDIS_PORT', 6379),
    'database' => env('REDIS_BROADCASTING_DB', 2),
   ],

   'cache' => [
    'host' => env('REDIS_HOST', '127.0.0.1'),
    'password' => env('REDIS_PASSWORD', null),
    'port' => env('REDIS_PORT', 6379),
    'database' => env('REDIS_CACHE_DB', 1),
   ],
  ],
];

filesystems.php

return [

 'default' => env('FILESYSTEM_DRIVER', 'local'),

 'cloud' => env('FILESYSTEM_CLOUD', 's3'),

 'disks' => [

  'local' => [
   'driver' => 'local',
   'root' => storage_path('app'),
  ],

  'public' => [
   'driver' => 'local',
   'root' => storage_path('app/public'),
   'url' => env('APP_URL').'/storage',
   'visibility' => 'public',
  ],

  's3' => [
   'driver' => 's3',
   'key' => env('AWS_ACCESS_KEY_ID'),
   'secret' => env('AWS_SECRET_ACCESS_KEY'),
   'region' => env('AWS_DEFAULT_REGION'),
   'bucket' => env('AWS_BUCKET'),
   'url' => env('AWS_URL'),
   'endpoint' => env('AWS_ENDPOINT'),
  ],

  'logs' => [
   'driver' => 'local',
   'root' => storage_path('logs'),
   'url' => env('APP_URL') . '/storage/logs',
  ],
 ],

];

Follow me!

前の記事

Laravel 構成

次の記事

Laravel ルーティング