Laravel
のartisan
コマンドで、動くことを想定したローカルパッケージを作りました。
忘れないよう書き残しておきます。
使用したソフトとバージョン
Name | Version |
---|---|
PHP | 7.4.15 |
Laravel | 8.29.0 |
やりたかったこと
touch database/database.sqlite
.env
を、コピー- マイグレーション
.envの一部分
LOG_CHANNEL=daily LOG_LEVEL=debug DB_CONNECTION=sqlite #DB_HOST=127.0.0.1 #DB_PORT=3306 #DB_DATABASE=laravel #DB_USERNAME=root #DB_PASSWORD=
結論
方法1
.env
をコピーするコマンドを実行させたら、一度、artisan
コマンドを終了させること。
新しい.env
を読み込んで貰わないと、いけないため。
php artisan fossa:install php artisan migrate
方法2
或いは、config()
で、設定する。
要点だけ、さらしておきます。
動かなかった
<?php <省略> use Illuminate\Console\Command; class FossaCommand extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'fossa:install'; <省略> /** * Execute the console command. * * @return void */ public function handle() { // touch touch(database_path('database.sqlite')); // Copy copy(__DIR__.'/../../files/.env', base_path('.env')); // migration //$this->call('migrate', ['--force' => true,]); $this->call('migrate'); } }
動いた
<?php <省略> use Illuminate\Console\Command; class FossaCommand extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'fossa:install'; <省略> /** * Execute the console command. * * @return void */ public function handle() { // touch touch(database_path('database.sqlite')); // Copy copy(__DIR__.'/../../files/.env', base_path('.env')); // Config config(['database.default' => 'sqlite']); config(['database.connections.sqlite.database' => database_path('database.sqlite')]); // migration //$this->call('migrate', ['--force' => true,]); $this->call('migrate'); } }
作業後記
上記は、あくまでも例えです。*1
今までは、独自でドキュメントを作成して、手作業でやっていました。
やるべきことが増えたので、一つのartisan
コマンドで出来たらいいなと思って、試してみました。
.env
は、コピーだけでなく、設定した後も想定して、実際は書き換えられるようにしてあります。
config
のapp.php
とか、すぐ使えるようになったら便利と思うことを追加する予定です。
*1:悪い例えかもしれません