belongsTo(User::class); } public static function Log(array $arr, int $user_id) { $data = []; foreach ($arr as $v) { $data[$v->type] = $v->value ?? 0; if ($v->type === 'locationEnabled') { if ($v->value == '开') { $value = 1; } else { $value = 0; } $data[$v->type] = $value; } if ($v->type === 'locationAuthorized') { if ($v->value == '已授权') { $value = 1; } else { $value = 0; } $data[$v->type] = $value; } } $data['user_id'] = $user_id; $data['detail'] = json_encode($arr); self::query()->updateOrCreate(['user_id' => $user_id], $data); } }