Run artisan command in laravel 5

paranoid picture paranoid · May 15, 2016 · Viewed 45.5k times · Source

I have controller like this

 public function store(Request $request)
{
   Artisan::call("php artisan infyom:scaffold {$request['name']} --fieldsFile=public/Product.json");
}

Show me error

There are no commands defined in the "php artisan infyom" namespace.

When I run this command in CMD it work correctly

Answer

Alexey Mezenin picture Alexey Mezenin · May 15, 2016

You need to remove php artisan part and put parameters into an array to make it work:

public function store(Request $request)
{
   Artisan::call("infyom:scaffold", ['name' => $request['name'], '--fieldsFile' => 'public/Product.json']);
}

https://laravel.com/docs/5.2/artisan#calling-commands-via-code