e282486518/laravel-table-sync
Composer 安装命令:
composer require e282486518/laravel-table-sync
包简介
使用api方式增量同步数据表
README 文档
README
使用方式
步骤一:
composer require e282486518/laravel-table-sync
步骤二: 继承服务
<?php namespace App\Services; use App\Models\Meeting; use e282486518\LaravelTableSync\SyncService; /** * 增量同步数据到c_meeting表 */ class MeetingSyncService extends SyncService { // A服务器API地址 protected string $apiUrl = 'https://api.xxx.com/api/meeting/sync'; // API令牌 protected string $apiToken = 'xxxxxx'; /** * 更新数据 * @param $id * @return void */ protected function afterUpdate($id): void { Meeting::getOne($id, true); } /** * 记录信息级别日志 * 子类可以重写此方法来自定义日志行为 * * @param string $message 日志消息 */ protected function logInfo(string $message): void { logger()->channel('other')->info($message); } /** * 记录错误级别日志 * 子类可以重写此方法来自定义日志行为 * * @param string $message 日志消息 */ protected function logError(string $message): void { logger()->channel('other')->error($message); } }
步骤三: 在命令行中调用
public function handle() { $serv = new MeetingSyncService(new Meeting()); if ($serv->sync()) { echo "更新成功...\n"; } else { echo "更新出错...\n"; } return Command::SUCCESS; }
步骤四: 执行命令
可以使用 php artisan xxxxx 执行第三步定义的命令
但是, 这里推荐使用 Schedule 执行命令, 参考laravel文档, 用一个cron命令管理项目中所有自动执行的命令
php artisan schedule:run
服务端代码
<?php namespace App\Http\Controllers; use App\Models\Meeting; use Illuminate\Http\Request; use Illuminate\Validation\ValidationException; class MeetingController extends Controller { /** * 增量更新数据 * @param Request $request * @return \Illuminate\Http\JsonResponse */ public function sync(Request $request) { // 最后更新时间 try { $request->validate([ 'time' => 'required|date_format:Y-m-d H:i:s', 'year' => 'date_format:Y', 'catid' => 'integer', ]); } catch (ValidationException $e) { // 自定义返回内容 return response()->json([ 'err' => 1, 'msg' => $e->errors(), 'data' => [] ], 200); } $time = $request->input('time'); $year = $request->input('year', 0); $catid = $request->input('catid', 0); // 获取更新的数据 $model = Meeting::query()->where('updated_at', '>', $time); if (!empty($year)) { $model->where('year', $year); } if (!empty($catid)) { $model->where('cat_id', $catid); } $meetings = $model->orderBy('updated_at', 'desc')->get(); // 最后更新时间 if (!$meetings->isEmpty()) { $latestUpdate = $meetings->first()->updated_at->format('Y-m-d H:i:s'); } else { $latestUpdate = $time; } // 返回 return response()->json([ 'err' => 0, 'msg' => 'success', 'data' => $meetings, 'latest_update' => $latestUpdate ])->setEncodingOptions(320); } }
e282486518/laravel-table-sync 适用场景与选型建议
e282486518/laravel-table-sync 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 36 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「api」 「laravel」 「eloquent」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 e282486518/laravel-table-sync 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 e282486518/laravel-table-sync 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 e282486518/laravel-table-sync 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
PHP module for MySql database
Alfabank REST API integration
统计信息
- 总下载量: 36
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-25