Search code examples
phplaravellaravel-artisanlaravel-5.8

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?


Solution

  • You can do:

    $fullClassName = "Nitseditor\\Plugins\\${pluginName}\\Databases\\seeds\\InstallSeeder";
    
    Artisan::call("db:seed", ['--class' => $class]);