Laravel配置Route调用artisan
作者:互联网
//web调用artisan
Route::get('/artisan', function(\Illuminate\Http\Request $request) {
$all = \Illuminate\Support\Facades\Artisan::all();
$cmd = $request->get('cmd', '');
if (empty($cmd) or !isset($all[$cmd])) {
return response()->make('404 Not Found', 404);
}
// key => value
$params = [];
foreach ($request->query() as $k => $v) {
if ($k == 'cmd') {
continue;
}
if (is_numeric($k)) {
$params[] = $k;
continue;
}
$params['--'.$k] = $v;
}
\Illuminate\Support\Facades\Artisan::call($cmd, $params);
return response()->make('done');
});
比如有artisan console任务
class SystemMail extends Command
{
protected $signature = 'system_mail_send {--email=}';
}
Web调用方法
http://www.host.com/route/artisan?cmd=system_mail_send&email=abc@qq.com
- 哈哈,超级入口,只是不支持artisan的argument,只支持option
为安全防范,可以在route加入JWT的token验证
标签:Laravel,调用,Illuminate,Route,cmd,request,params,artisan 来源: https://www.cnblogs.com/imbin/p/12599060.html