|
8 | 8 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
9 | 9 | use Illuminate\Foundation\Auth\User as Authenticatable; |
10 | 10 | use Illuminate\Notifications\Notifiable; |
11 | | -use Illuminate\Support\Facades\DB; |
12 | 11 | use Illuminate\Support\Str; |
13 | 12 | use Moox\Press\Database\Factories\WpUserFactory; |
14 | 13 |
|
@@ -273,23 +272,16 @@ protected function getMeta($key) |
273 | 272 |
|
274 | 273 | protected function addOrUpdateMeta($key, $value) |
275 | 274 | { |
276 | | - $exists = DB::table($this->metatable) |
277 | | - ->where('user_id', $this->ID) |
278 | | - ->where('meta_key', $key) |
279 | | - ->exists(); |
| 275 | + $meta = $this->userMeta()->where('meta_key', $key)->first(); |
280 | 276 |
|
281 | | - if ($exists) { |
282 | | - DB::table($this->metatable) |
283 | | - ->where('user_id', $this->ID) |
284 | | - ->where('meta_key', $key) |
285 | | - ->update(['meta_value' => $value]); |
| 277 | + if ($meta) { |
| 278 | + $meta->meta_value = $value; |
| 279 | + $meta->save(); |
286 | 280 | } else { |
287 | | - DB::table($this->metatable) |
288 | | - ->insert([ |
289 | | - 'user_id' => $this->ID, |
290 | | - 'meta_key' => $key, |
291 | | - 'meta_value' => $value, |
292 | | - ]); |
| 281 | + $this->userMeta()->create([ |
| 282 | + 'meta_key' => $key, |
| 283 | + 'meta_value' => $value, |
| 284 | + ]); |
293 | 285 | } |
294 | 286 | } |
295 | 287 | } |
0 commit comments