Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/al-one/laravel-replace-into

SQL replace into For Laravel
https://github.com/al-one/laravel-replace-into

eloquent laravel

Last synced: 3 months ago
JSON representation

SQL replace into For Laravel

Awesome Lists containing this project

README

        

# SQL replace into For Laravel

## Installing

```
# composer.json

"minimum-stability": "dev",
"prefer-stable": true,
```

```sh
$ composer require "al-one/laravel-replace-into" -vvv
```

## Usage

```php
# optional if >= 5.5
# config/app.php
[
Alone\LaravelReplaceInto\ServiceProvider::class,
],

];
```

```php
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']);
```

```php
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