Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing seed command dynamically through controller in Laravel

I'm trying to build a small application on Laravel with modular approach, I am having a controller method which seeds the database as per the module/plugin name:

I have something like this:

Artisan::call('db:seed --class=Nitseditor\\Plugins\\'.$pluginName.'\\Databases\\seeds\\InstallSeeder');

Whenever I am calling this I am getting this error in my console.

Class NitseditorPluginsConfidenceDatabasesseedsInstallSeeder does not exist

I don't know why it remove \ and concatenate the strings.

How can I achieve this?

like image 528
Nitish Kumar Avatar asked Jun 04 '26 18:06

Nitish Kumar


1 Answers

You can do:

$fullClassName = "Nitseditor\\Plugins\\${pluginName}\\Databases\\seeds\\InstallSeeder";

Artisan::call("db:seed", ['--class' => $class]);
like image 176
gbalduzzi Avatar answered Jun 07 '26 08:06

gbalduzzi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!