Hello everyone!
When working on a Laravel 5 project and creating a new seeder, we add it to our DatabaseSeeder. In this example, we have added the ReportsTableSeeder seeder, leaving our DatabaseSeeder file as follows:
<?php use Illuminate\Database\Seeder; class DatabaseSeeder extends Seeder { /** * Run the database seeds. * * @return void */ public function run() { $this->call(UsersTableSeeder::class); $this->call(ReportsTableSeeder::class); } }
So far so good, when we run
php artisan migrate --seed
Sometimes it throws the following error:
[ReflectionException] Class ReportsTableSeeder does not exist
Here we have different options, I will list the ones that occur to me at this moment:
Once we confirm that all this is fine and we do not have any of these problems, that is, our file exists within the seeders folder of our project and the name of the class is correct, the solution to this is to clear the cache and optimize our Loader for this let's see the solution
We execute all these commands in the following order:
php artisan optimize php artisan cache:clear php artisan route:clear php artisan view:clear php artisan config:clear
It is not necessary to execute them all, but I recommend doing so if you are in the development phase.
Once these commands have been executed one by one, we must delete the tables created previously by executing:
php artisan migrate --seed
If it gives an error, it is likely that we have other seeders before our not found seeder, and this has created the other tables. To solve this, we access our database and delete the created tables. Once the tables have been deleted, we repeat the process by executing:
php artisan migrate --seed
And finally now we can process our ReportsTableSeeder seeder 😀
I hope it helps more than one person.
Page loaded in 35.99 ms