Multi-Update is a laravel package that allows you to update multiple rows in a database table with a single SQL statement. This package is useful when you need to update multiple rows with different values based on different conditions.
You can install Multi-Update using Composer.
composer require pedram/multi-update
To use Multi-Update, you need to call the updateMultipleRows
method on a model or a query builder instance. This method takes two parameters: an array of fields and their corresponding values to update, and a variable-length argument list of conditions to apply to the update statement.
use PedramD\MultiUpdate\MultiUpdate;
MyModel::updateMultipleRows($params, $condition1, $condition2, ...);
Here's an example of how you can use Multi-Update to update multiple rows in a database table:
use PedramD\MultiUpdate\MultiUpdate;
MyModel::updateMultipleRows([
'column1' => [
'condition1' => 'value1',
'condition2' => 'value2',
'condition3' => 'value3',
],
'column2' => [
'condition4' => 'new_value',
],
], 'column5 > 0', 'column6 = "some_value"');
In the above example, we are updating two columns column1
and column2
. The column1
is updated based on three different conditions, and the column2
is updated based on one condition. We have also added two additional conditions to apply to the update statement.
Contributions to Multi-Update are welcome and encouraged! If you find a bug or have a feature request, please open an issue on the GitHub repository. If you would like to contribute code, please fork the repository and submit a pull request.
When submitting a pull request, please make sure to follow the PSR-2 coding standards for any new functionality or bug fixes.
Multi-Update is open-sourced software licensed under the MIT license.