PHP code example of rits-tecnologia / eloquent-insert-on-conflict

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

    

rits-tecnologia / eloquent-insert-on-conflict example snippets


InsertOnConflict\InsertOnConflictServiceProvider::class,

$data = [
    ['id' => 1, 'name' => 'name1', 'email' => '[email protected]'],
    ['id' => 2, 'name' => 'name2', 'email' => '[email protected]'],
];

User::insertOnConflict($data);


User::insertOnConflict([
    'id'    => 1,
    'name'  => 'new name',
    'email' => '[email protected]',
], ['name'], 'do update set', 'id');
// The name will be updated but not the email.

User::insertOnConflict([
    'id'    => 1,
    'name'  => 'created user',
], ['name' => 'updated user'], 'do update set', 'id');

User::insertOnConflict([
    'id'       => 1,
    'name'     => 'created user',
    'email'    => '[email protected]',
    'password' => 'secret',
], ['name' => 'updated user', 'email'], 'do update set', 'id');