Skip to content

Conversation

@ycs77
Copy link
Contributor

@ycs77 ycs77 commented May 25, 2023

Add HasBatch trait for model, that it can be called statically.

Usage

Add HasBatch trait into model:

namespace App\Models; use Mavinoo\Batch\Traits\HasBatch; class User extends Model { use HasBatch; }

Call batchUpdate() from model:

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:

$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);
@ycs77 ycs77 changed the title Add HasBatch trait for model Static call from model May 25, 2023
@mavinoo mavinoo merged commit 98cd248 into mavinoo:master May 29, 2023
@ycs77 ycs77 deleted the add-trait-for-model branch May 29, 2023 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants