【问题标题】:Running Artisan Command from laravel 4.2 Controller从 laravel 4.2 控制器运行 Artisan 命令
【发布时间】:2016-05-09 14:20:32
【问题描述】:

我正在尝试从控制器执行一些自定义工匠命令,例如

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

但是当我执行时它工作正常

php artisan MuCustomCommand from CLI

我已经在app/start/artisan.php.注册了命令 即使Artisan::call('php artisan --help'); 也不起作用。

【问题讨论】:

  • 你在运行 php artisan 时看到你的自定义命令了吗??
  • 是的,我的自定义命令在命令列表中。
  • 你有什么错误或什么吗??
  • 我认为使用 laravel 4.2 你不能通过代码运行命令。因为他们的文档也没有显示任何与此相关的信息。由于您使用的代码在 laravel 5.1 和 5.2 中可用,您必须在 app/Console/Kernel.php 文件中注册您的命令。
  • Artisan::call('php artisan MyCustomCommand') 执行时返回“InvalidArgumentException Command "php artisan CustomCommand" is not defined。”

标签: php laravel-artisan laravel-4.2


【解决方案1】:

你应该从你的控制器运行这样的工匠命令。 示例:

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

所以不要做Artisan::call('php artisan MyCustomCommand');

你应该这样做

Artisan::call('MyCustomCommand');

这里是documentation

希望对你有帮助:)

【讨论】:

    猜你喜欢
    • 2017-10-14
    • 1970-01-01
    • 2016-07-30
    • 2015-04-06
    • 2018-07-01
    • 1970-01-01
    • 2019-02-17
    • 2020-01-30
    • 2016-09-24
    相关资源
    最近更新 更多