【发布时间】:2016-06-20 20:30:04
【问题描述】:
问题/我尝试过的:
在 Laravel 5 中获取当前使用的控制器和动作很容易(但没有应有的那么容易),但是我一直坚持获取当前使用的工匠控制台命令。
要获取控制器名称,我这样做:
$route = Route::getRoutes()->match(Request::capture());
$listAction = explode('\\', $route->getActionName());
$rawAction = end($listAction);
// controller name and action in a simple array
$controllerAndAction = explode('@', $rawAction);
但是当从控制台操作调用时,它总是返回默认索引控制器的名称(Laravel 中的“IndexController”左右)。有人知道怎么做吗?
顺便说一句,我也通过Request::capture() 工作过,但这仍然没有提供有关该命令的信息。
【问题讨论】:
-
But when calling from a console action, it always returns the default index controller's name你如何从命令行调用它? -
@TheAlpha 通过 php artisan mycommand
-
您实际上需要了解有关您的命令的哪些信息?它的名字?
-
从控制台运行时没有请求。该请求仅在您使用
HttpKernel 时可用。
标签: php laravel laravel-artisan