Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/al-one/laravel-replace-into
- Owner: al-one
- License: mit
- Created: 2019-04-30T09:38:35.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-09-17T06:43:15.000Z (over 1 year ago)
- Last Synced: 2024-05-21T12:52:30.923Z (8 months ago)
- Topics: eloquent, laravel
- Language: PHP
- Size: 6.84 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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