al-one/laravel-replace-into

SQL replace into for Laravel

v1.9.0-beta1 2022-08-04 10:45 UTC

This package is auto-updated.

Last update: 2024-11-17 09:08:26 UTC


README

Installing

# composer.json

"minimum-stability": "dev",
"prefer-stable": true,
$ composer require "al-one/laravel-replace-into" -vvv

Usage

# optional if >= 5.5
# config/app.php
<?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'],
]);

License

MIT