PHP code example of viktorruskai / advanced-upsert-for-laravel

1. Go to this page and download the library: Download viktorruskai/advanced-upsert-for-laravel 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/ */

    

viktorruskai / advanced-upsert-for-laravel example snippets


       ItemAction::upsert(
           [
               [
                   'itemId' => 1,
                   'actionName' => 'Purchased',
                   'actionDescription' => 'Test description',
                   'actionValue' => 12,
               ],
               // ... (more items) 
           ], 
           ['itemId', 'actionName'], // Conflict (either columns or key name)
           ['actionDescription'] // Update column 
       );
       

        ItemActionAdditional::upsert(
            [
                [
                    'where' => [
                        'itemId' => 1,
                        'actionName' => 'Test',
                    ],
                    'upsert' => [
                        'itemActionId' => '*' // Must be set `*`, this ID will be automatically added from `$selectModelClassName` by conditions from `where` param  
                        'specialData' => '123456',
                        'description' => 'Hello',
                    ], 
                ],
                // ... (more items)
            ], 
            ['itemActionId', 'specialData'], // Must be set as unique key (name of columns must be presented or name of the key) 
            ['description'], // Columns that will be updated
            ItemAction::class, // Eloquent model, in this case must be set
            [...] // Any columns that should be returned (Not