Repository navigation
Laravel Batch v3.0.0
A major release that rewrites how queries are built. Every 2.x user should upgrade:
all 2.x versions build SQL by escaping values by hand, which allows SQL injection
(always on PostgreSQL, and through index values and JSON keys on every database).
3.0 sends every value as a bound parameter and lets Laravel's grammar quote every
column and table name.
composer require "mavinoo/laravel-batch:^3.0"
Requires PHP 8.1+ and Laravel 10 – 13. Upgrading from 2.x takes a few
minutes for most projects: see the upgrade guide.
Breaking changes
- The
$rawargument is removed. Wrap only the values that are SQL inDB::raw():
['id' => 1, 'score' => DB::raw('score * 2')]. Passingtruefor the old argument
throws, so a missed call never stores SQL as text. - Update methods return
intandinsert()returnsarray. Empty input returns
0/ zero counts instead offalse. - Invalid input throws
InvalidArgumentExceptionbefore anything is written. BatchInterfaceandBatchdeclare return types.Mavinoo\Batch\Common\Commonand the globalstr()helper are removed.
Added
- Laravel 13 support.
DB::raw()in values, index values and conditions.- Enum values in every method.
- Batches over the database's bound parameter limit are split automatically and
run in one transaction on the model's connection. - A test suite (
composer test) and GitHub Actions on PHP 8.1 – 8.5,
Laravel 10 – 13, MySQL, MariaDB, PostgreSQL and SQLite.
Fixed
- Quotes, backslashes, JSON, leading zeros and booleans are stored exactly as
given (#66, #68, #70, #73, #76, #96, #101). - Every method works on PostgreSQL and SQLite (#116).
updateMultipleCondition()with string keys, on PostgreSQL, withnull
conditions, and when a condition column is updated in the same call on MySQL.updated_atonly changes for rows that change, on every database (#120).- Models with
CREATED_ATorUPDATED_ATset tonull(#107). insert()rolls back on the model's own connection, and$insertIgnoreworks
on PostgreSQL and SQLite.
Full changelog: https://github.com/mavinoo/laravelBatch/blob/v3.0.0/CHANGELOG.md
Pull request: #124