PHP code example of talentasia / eloquent-insert-on-duplicate-key

1. Go to this page and download the library: Download talentasia/eloquent-insert-on-duplicate-key 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/ */

    

talentasia / eloquent-insert-on-duplicate-key example snippets


use Illuminate\Database\Eloquent\Model;
use TalentAsia\InsertOnDuplicateKey;

/**
 * Class User.
 */
class User extends Model
{
    // The function is implemented as a trait.
    use InsertOnDuplicateKey;
}

    $users = [
        ['id' => 1, 'email' => '[email protected]', 'name' => 'User 1'],
        ['id' => 2, 'email' => '[email protected]', 'name' => 'User 2'],
        ['id' => 3, 'email' => '[email protected]', 'name' => 'User 3'],
    ];

    User::insertOnDuplicateKey($users);

    User::insertOnDuplicateKey($users, ['email']);

    User::insertIgnore($users);

    User::replace($users);

['id' => 1, 'email' => '[email protected]', 'name' => 'User One', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]