laravel-5 - 通过 URL 调用 Artisan Command

标签 laravel-5 laravel-artisan

在我的路线上有

Route::get('artisan/{command}/{param}', 'CacheController@show');

在我的 Controller 中有

public function show($id, $param)
{
    $artisan = Artisan::call($id,['flag'=>$param]);
    $output = Artisan::output();
    return $output;
}

我希望能够通过访问 domain.com/artisan/cache/clear 来调用 route:cachecache:clear 或者route/cache 但是当我调用它们时它返回了这样的东西

Command "cache" is not defined.

只调用了cache,没有调用cache:clear有什么可能出错?

最佳答案

当你调用 command 时,你正在调用一个 id

所以你的函数需要看起来像这样

public function show($command, $param) {
    $artisan = Artisan::call($command,['flag'=>$param]);
    $output = Artisan::output();
    return $output;
}

所以你的 URL 看起来像这样 domain.com/artisan/cache/clear 这意味着你正在调用这个路由

Route::get('artisan/{command}/{param}', 'CacheController@show');

所以你需要 $command 而不是 $id

关于laravel-5 - 通过 URL 调用 Artisan Command,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49877156/

相关文章:

php - 如何在 Laravel 5 中测试自定义验证规则?

php - 字符串作为 Laravel 迁移中的主键

php - 拉拉维尔 5 : jQuery Typeahead gives error status 500 on page load (Missing argument)

laravel-5 - 拉拉维尔 5 : How to get config value in artisan console command

php - Laravel DataTables Yajrabox 不显示数据

php artisanserve --host 0.0.0.0 无法从同一网络上的移动设备访问

laravel - Laravel 项目中的存储文件夹未提交到 github

php - 创建可过滤/可排序的 HTML 表

laravel - 队列 worker :queue-worker_00: ERROR (spawn error) Laravel Supervisor CentOS 7

rest - laravel/lumen REST API 间歇性地修改 env 并使用 'forge' 数据库