Skip to content

Commit a6bcd72

Browse files
committed
Update WpUser.php
1 parent 25808d8 commit a6bcd72

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/Models/WpUser.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Illuminate\Database\Eloquent\Factories\HasFactory;
99
use Illuminate\Foundation\Auth\User as Authenticatable;
1010
use Illuminate\Notifications\Notifiable;
11-
use Illuminate\Support\Facades\DB;
1211
use Illuminate\Support\Str;
1312
use Moox\Press\Database\Factories\WpUserFactory;
1413

@@ -273,23 +272,16 @@ protected function getMeta($key)
273272

274273
protected function addOrUpdateMeta($key, $value)
275274
{
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();
280276

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();
286280
} 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+
]);
293285
}
294286
}
295287
}

0 commit comments

Comments
 (0)