Closed ycs77 closed 1 year ago
Add HasBatch trait for model, that it can be called statically.
HasBatch
Add HasBatch trait into model:
namespace App\Models; use Mavinoo\Batch\Traits\HasBatch; class User extends Model { use HasBatch; }
Call batchUpdate() from model:
batchUpdate()
use App\Models\User; $values = [ [ 'id' => 1, 'status' => 'active', 'nickname' => 'Mohammad' ], [ 'id' => 5, 'status' => 'deactive', 'nickname' => 'Ghanbari' ], ]; $index = 'id'; User::batchUpdate($values, $index);
Call batchInsert() from model:
batchInsert()
$columns = [ 'firstName', 'lastName', 'email', 'isActive', 'status', ]; $values = [ [ 'Mohammad', 'Ghanbari', 'emailSample_1@gmail.com', '1', '0', ], [ 'Saeed', 'Mohammadi', 'emailSample_2@gmail.com', '1', '0', ], [ 'Avin', 'Ghanbari', 'emailSample_3@gmail.com', '1', '0', ], ]; $batchSize = 500; // insert 500 (default), 100 minimum rows in one query User::batchInsert($columns, $values, $batchSize);
Add
HasBatch
trait for model, that it can be called statically.Usage
Add
HasBatch
trait into model:Call
batchUpdate()
from model:Call
batchInsert()
from model: