chack1172/laravel-single-save
最新稳定版本:1.0.0
Composer 安装命令:
composer require chack1172/laravel-single-save
包简介
Optimize model saving with single save execution
README 文档
README
This package is designed to optimize the model saving process of your Laravel applications. Wrapping the code in a specific method callback performs a single database update at the end of the callback execution. This optimizes the application's performance, especially during complex transactions or scenarios with frequent model updates.
Installation
- Install the package using composer:
composer require chack1172/laravel-single-save
- Add the Eloquent trait to your models:
<?php ... use Chack1172\SingleSave\Eloquent\SingleSave; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use SingleSave; }
Usage
Wrap all the queries inside singleSave method:
class User extends Authenticatable { use SingleSave; public function updateName($name) { $this->name = $name; $this->save(); } public function updatePassword($password) { $this->password = $password; $this->save(); } } // ... $user->singleSave(function ($user) { $user->updateName('Marco Rossi'); $user->updatePassword('1234'); });
This code will run a single query when the callback is terminated updating both name and password in the database.
License
This project is licensed under the MIT License. Please see License File for more information.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-07-18