Executing a Route (Controller/Action) using PHP CLI and Detecting a CLI Request

依然范特西╮ 提交于 2019-12-01 06:56:25

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!