Is there a way in Laravel 4 to run my controller/action using PHP-CLI? I have a controller/action that I would like to extend to perform an alternative action if the request
As Rob already said, to determine if the current script is being run in the console use App::runningInConsole()
or simple plain PHP php_sapi_name() == 'cli'
.
As for running controller@action from console, you could use curl
or wget
to request one of your routes but I think the proper way of doing it would be to use a custom artisan command. Your controllers are classes so you can instantiate them and use as you please from within your artisan command:
$controller = new SomeController;
$controller->someAction();
Watch this video for an introduction to easily developing your own artisan commands.