前提・実現したいこと
PHP(Laravel5.7)で掌田 津耶乃 著の「Laravel入門」を参考にしながらシードの作成を行っています。
発生している問題・エラーメッセージ
その途中でphp artisan db:seed
で実行しようとしたら以下のようなエラーメッセージが出てきました(エラーメッセージ1)。
さらに、それを改善しようとしてcomposer dump-autoload
をやっても以下のようなエラーコードが出てきてしまいます(エラーメッセージ2)。
PHP, Laravelを学習し始めて1年ほどしかたたない未熟者故、対処しかねております。助言の程よろしくお願いいたします。
エラーメッセージ1 [vagrant@localhost myblog]$ php artisan db:seed Seeding: RestdataTableSeeder ReflectionException : Class RestdataTableSeeder does not exist at /home/vagrant/laravel_lessons/myblog/vendor/laravel/framework/src/Illuminate/Container/Container.php:779 775| if ($concrete instanceof Closure) { 776| return $concrete($this, $this->getLastParameterOverride()); 777| } 778| > 779| $reflector = new ReflectionClass($concrete); 780| 781| // If the type is not instantiable, the developer is attempting to resolve 782| // an abstract type such as an Interface or Abstract Class and there is 783| // no binding registered for the abstractions so we need to bail out. Exception trace: 1 ReflectionClass::__construct("RestdataTableSeeder") /home/vagrant/laravel_lessons/myblog/vendor/laravel/framework/src/Illuminate/Container/Container.php:779 2 Illuminate\Container\Container::build("RestdataTableSeeder") /home/vagrant/laravel_lessons/myblog/vendor/laravel/framework/src/Illuminate/Container/Container.php:658 Please use the argument -v to see more details.
エラーメッセージ2 [vagrant@localhost myblog]$ composer dump-autoload Generating optimized autoload files [RuntimeException] File at "/home/vagrant/laravel_lessons/myblog/app/Http/Controllers/BoardController.php" does not ex ist, check your classmap definitions dump-autoload [--no-scripts] [-o|--optimize] [-a|--classmap-authoritative] [--apcu] [--no-dev]
該当のソースコード
ソースコード1 <?php namespace App; use Illuminate\Database\Eloquent\Model; class Restdata extends Model { // protected $table = 'restdata'; protected $guarded = array('id'); public static $rules = array( 'message' => 'required', 'url' => 'required' ); public function getData() { return $this->id . ':' . $this->message . '(' . $this->url . ')'; } }
ソースコード2 <?php use Illuminate\Database\Seeder; use App\Restdata; class RestdataTableSeeder extends Seeder { public function run() { $param = [ 'message' => 'Google Japan', 'url' => 'http://www.google.co.jp', ]; $restdata = new Restdata; $restdata->fill($param)->save(); $param = [ 'message' => 'Yahoo Japan', 'url' => 'https://www.yahoo.co.jp', ]; $restdata = new Restdata; $restdata->fill($param)->save(); $param = [ 'message' => 'MSM Japan', 'url' => 'http://www.msn.com/ja-jp', ]; $restdata = new Restdata(); $restdata->fill($param)->save(); } }
ソースコード3 <?php use Illuminate\Database\Seeder; class DatabaseSeeder extends Seeder { /** * Seed the application's database. * * @return void */ public function run() { // $this->call(UsersTableSeeder::class); $this->call(RestdataTableSeeder::class); } }
試したこと
php artisan make:seeder RestdataTableSeeder
でシーダーファイルを作成後、DatabaseSeederにこのクラスを登録。その後、問題の「php artisan db:seed」を実行。エラーメッセージ1が発生した。
改善を試みてcomposer dump-autoload
をやるとエラーメッセージ2が発生。
補足情報(FW/ツールのバージョンなど)
PHP Version 7.1.26
Laravel Version 5.7.26
仮想サーバOS CentOS 6.8
Laravel開発環境はドットインストールさんを参考にさせていただきました。そのため、本書に書いてある開発環境ではないです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/26 14:23
2019/02/26 23:09
2019/02/27 01:56
2019/02/27 04:23