refactor: update user relationship in PushSubscription model and clean up User model attributes

This commit is contained in:
Yoga Pangestu 2026-08-05 23:29:37 +07:00
parent 4ac83c8e78
commit 3b49f5ff3a
2 changed files with 7 additions and 10 deletions

View File

@ -6,14 +6,15 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;
#[Guarded(['id'])]
class PushSubscription extends Model
{
use HasFactory;
public function user(): BelongsTo
public function user(): MorphTo
{
return $this->belongsTo(User::class);
return $this->morphTo();
}
}

View File

@ -10,6 +10,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
@ -37,21 +38,21 @@ protected function casts(): array
protected function email(): Attribute
{
return Attribute::make(
set: fn (string $value) => strtolower($value),
set: fn(string $value) => strtolower($value),
);
}
protected function name(): Attribute
{
return Attribute::make(
get: fn () => $this->userProfile?->full_name ?? '',
get: fn() => $this->userProfile?->full_name ?? '',
);
}
protected function fullName(): Attribute
{
return Attribute::make(
get: fn () => $this->userProfile?->full_name ?: $this->username,
get: fn() => $this->userProfile?->full_name ?: $this->username,
);
}
@ -181,11 +182,6 @@ public function purchaseItems(): HasMany
return $this->hasMany(PurchaseItem::class);
}
public function pushSubscriptions(): HasMany
{
return $this->hasMany(PushSubscription::class);
}
public function rejections(): HasMany
{
return $this->hasMany(Rejection::class, 'rejected_by_id');