Optimize model saving with single save execution
chack1172/laravel-single-save is a Laravel package for optimize model saving with single save execution.
It currently has 0 GitHub stars and 5 downloads on Packagist (latest version 1.0.0).
Install it with composer require chack1172/laravel-single-save.
Discover more Laravel packages by chack1172
or browse all Laravel packages to compare alternatives.
Last updated
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.
composer require chack1172/laravel-single-save
<?php
...
use Chack1172\SingleSave\Eloquent\SingleSave;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use SingleSave;
}
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.
This project is licensed under the MIT License. Please see License File for more information.