在我的路线上有
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:cache
和 cache: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/