実現したいこと
Laravelでバッチ作成
前提
AWSのEC2上で無料枠のCentOS7を選択し(ストレージを30GiB)インスタンスを作成しました。
次に、MySQL,Nginx,PHP,Laravelをそれぞれインストールしました。バージョンは以下です。
mysqld Ver 5.7.31 for Linux on x86_64
nginx/1.18.0
PHP 7.3.20
Laravel7
その後VSCodeのRemoteSSH機能を使って、サーバ側にWindows経由でSSH接続しました。
MySQLでDBを作成後、VSCodeでホストサーバにアクセスし、TestCommand.php内部を編集しました。
【TestCommand.php】 <?php namespace App\Console\Commands; use Illuminate\Console\Command; use App\Models\Player; class TestCommand extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'test_command'; /** * The console command description. * * @var string */ protected $description = 'Test Command'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return int */ public function handle() { $players = Player::get(); foreach($players as $player) { echo $player->name."\n"; } return 0; } }
php artisan test_commandをターミナル上で打ち込み、
DB上のサッカー選手名を表示させたいのですが、
以下のエラーが表示されます。
発生している問題・エラーメッセージ1
[centos@ip-xxx-xx-xx-xxx host]$ php artisan test_command ErrorException Undefined index: driver at vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php:127 123| 124| // Next we will check to see if an extension has been registered for a driver 125| // and will call the Closure if so, which allows us to have a more generic 126| // resolver for the drivers themselves which applies to all connections. > 127| if (isset($this->extensions[$driver = $config['driver']])) { 128| return call_user_func($this->extensions[$driver], $config, $name); 129| } 130| 131| return $this->factory->make($config, $name); +10 vendor frames 11 app/Console/Commands/TestCommand.php:41 Illuminate\Database\Eloquent\Model::__callStatic("get", []) +14 vendor frames 26 artisan:37 Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
試したこと
1.mysqlの停止・再起動
2.mysqlのパスワード変更(#を含んでおりエラーに関わると感じ!に変更)
3.DatabaseManager.phpの127行目の"driver"が未定義であるためエラーかと思いましたが、変更の仕方が分からない。
4.TestCommand.phpの41行目、"get", []部分の変更かと思いましたがこちらもいじらずそのままです。
発生している問題・エラーメッセージ2
[centos@ip-xxx-xx-xx-xxx host]$ php artisan optimize && php artisan route:cache Configuration cache cleared! Configuration cached successfully! Route cache cleared! LogicException Unable to prepare route [/] for serialization. Uses Closure. at vendor/laravel/framework/src/Illuminate/Routing/Route.php:1150 1146| */ 1147| public function prepareForSerialization() 1148| { 1149| if ($this->action['uses'] instanceof Closure) { > 1150| throw new LogicException("Unable to prepare route [{$this->uri}] for serialization. Uses Closure."); 1151| } 1152| 1153| $this->compileRoute(); 1154| +27 vendor frames 28 artisan:37 Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
試したこと
1.Route.phpの1150行目に何かしらの準備ができていない。
「Unable to prepare route [/] for serialization」に関しては、ルートの準備ができていないと記載されているが、どのような変更を施すべきか理解不能。
補足情報(FW/ツールのバージョンなど)
【開発環境】
Windows 10 Pro 64bit
Surface Pro 4
回答1件
あなたの回答
tips
プレビュー