Running Artisan Command from laravel 4.2 Controller
Asked Answered
K

1

5

I am trying to execute some custom artisan command from controller like

Artisan::call('php artisan MyCustomCommand');

but it works fine when I execute

php artisan MuCustomCommand from CLI.

I have registered command in app/start/artisan.php. Even Artisan::call('php artisan --help'); is not working.

Kozak answered 1/2, 2016 at 7:47 Comment(7)
do you see your custom command when you run php artisan ??Dobbins
yes, my custom command is there on list of command.Kozak
do you have any error or anything ??Dobbins
I think by using laravel 4.2 you can't run the command via code. As their documentation is also not showing any information related to this. As the code which you have used it is available in laravel 5.1 and 5.2 where you have to register your command in app/Console/Kernel.php file.Stillborn
When Artisan::call('php artisan MyCustomCommand') is executed, it returns "InvalidArgumentException Command "php artisan CustomCommand" is not defined."Kozak
For this error registered your CustomCommand class in app.php file e.g. View, Request , Sessions are have aliases.Stillborn
@Kozak did you check the answer ???Dobbins
D
8

You should run artisan command like this from your controller . Example :

 Artisan::call('migrate:install');

So Instead of doing Artisan::call('php artisan MyCustomCommand');

You should do

Artisan::call('MyCustomCommand');

Here is the documentation

Hope it helps :)

Dobbins answered 1/2, 2016 at 8:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.