I have a scenario where I need to un specific seeders in order to populate some default data for database tables.
The seeders need to be run via code inside some controller(s).
But when I use
Artisan::call('db:seed');
it throws me errors like
SeederClass Not Found
From documentation, I understand to use composer dumpautoload before actually running new seeders and when I do the same via terminal everything works fine.
How can I fix the issue when running seeders via code inside Laravel Controllers.
Any valuable suggestions are highly obliged. Thank You.
@zahidnazirkhan You could simply call the run function of your seeder(s) directly.
// For example
(new DatabaseSeeder)->run();
Why exactly do you want to run seeders inside your controllers tho? Are you sure there isn't another way around that? If possible you should seed your database once using the artisan command.
Actually, the reason is over time new changes are added to the system and so are new tables (and their default values).
So when a user takes an update, new functionalities in the form of migrations & seeders needs to be run. At that time I am running Artisan::call('db:seed');from within a controller. End users are not supposed to run terminal commands.
For fresh installations, everything works fine via terminal using artisan commands.
So when a user takes an update, new functionalities in the form of migrations & seeders needs to be run
Do you have to use migrations/seeders for that? I don't exactly know what those changes look like, but maybe it's better if you wrap them inside an action?