PHP code example of al-one / laravel-replace-into

1. Go to this page and download the library: Download al-one/laravel-replace-into 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/ */

    

al-one / laravel-replace-into example snippets


# optional if >= 5.5
# config/app.php


return [

    'providers' => [
        Alone\LaravelReplaceInto\ServiceProvider::class,
    ],

];

use Illuminate\Support\Facades\DB;

DB::table('user_attrs')->replace(
    ['uid' => 10000,'type' => 'key','value' => 'val'],
    ['uid','type'] // uniqueKeys
);

DB::table('user_attrs')->replace([
    ['uid' => 10000,'type' => 'key1','value' => 'val1'],
    ['uid' => 10001,'type' => 'key2','value' => 'val2'],
],['uid','type']);

use Illuminate\Database\Eloquent\Model;

class UserAttr extends Model
{
    public function uniqueKeys()
    {
        return ['uid','type'];
    }
}

UserAttr::replace(
    ['uid' => 10000,'type' => 'key','value' => 'val']
);

UserAttr::replace([
    ['uid' => 10000,'type' => 'key1','value' => 'val1'],
    ['uid' => 10001,'type' => 'key2','value' => 'val2'],
]);