PHP code example of free3_5man / laravel-eloquent-batch
1. Go to this page and download the library: Download free3_5man/laravel-eloquent-batch library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
free3_5man / laravel-eloquent-batch example snippets
use App\Models\Player;
use Freeman\LaravelBatch\BatchUtil;
$data = [
// this is the first item, columns of this item will be used as insert columns
// if columns of any other items does not equal to this, false will be returned as result
// all the columns of each item olumns default;
$ids = BatchUtil::ofModel(new Player)->batchInsert($data);
// if players primay key auto_increment, insert ids array ([1, 2, 3]) will be returned, else empty array ([]) will be returned
$data[1]['is_captain'] = true;
BatchUtil::ofModel(new Player)->batchInsert($data); // return false