Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run artisan command in laravel 5

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

like image 852
paranoid Avatar asked May 15 '16 08:05

paranoid


People also ask

How do I run artisan command in Laravel controller?

So we can do it by using Artisan facade. In Laravel Artisan facade that way we can easily run the all artisan command also with argument. So Artisan facade have two method one call() and another one is queue() through we can simply make process in call like seeder and also migration run etc.

How do I run php artisan serve command?

In Laravel, we can run Laravel Development server by typing php artisan serve command on terminal or command line. Make sure your in Laravel's project root directory. If not change your present working directory.


1 Answers

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

like image 97
Alexey Mezenin Avatar answered Oct 04 '22 12:10

Alexey Mezenin