Laravel中任务调度console使用方法小结
原创
©著作权归作者所有:来自51CTO博客作者qq58fdc80357c56的原创作品,请联系作者获取转载授权,否则将追究法律责任
适用场景:分析数据(日志)
php artisan make:testUpdateUserHuanxinId 你的命令类名
示例:
php artisan make:console testUpdateUserHuanxinId
Commands目录下已生成一个testUpdateUserHuanxinId .php文件
<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
class testUpdateUserHuanxinId extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'UpdateUserHuanxinId';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
* 写自己的业务逻辑
* @return mixed
*/
public function handle()
{
$userInfo = User::get();
foreach ($userInfo as $k=>$v) {
$isEasemob = User::createEasemob($v['id'],0,1);
dump($isEasemob);
// User::where('id',$userInfo->id)->update(['email' => 'test' . $userInfo->email]);
}
}
}
命令行里面执行 php artisan UpdateUserHuanxinId