42 lines
923 B
PHP
42 lines
923 B
PHP
<?php
|
|
|
|
namespace App\Domains\Workspace\Models;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class WorkspaceInvitation extends Model
|
|
{
|
|
protected $guarded = ['id'];
|
|
|
|
protected $casts = [
|
|
'expires_at' => 'datetime',
|
|
'accepted_at' => 'datetime',
|
|
];
|
|
|
|
/** @return BelongsTo<Workspace, $this> */
|
|
public function workspace(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Workspace::class);
|
|
}
|
|
|
|
/** @return BelongsTo<User, $this> */
|
|
public function invitedBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'invited_by');
|
|
}
|
|
|
|
public function isExpired(): bool
|
|
{
|
|
$expiresAt = $this->getAttribute('expires_at');
|
|
|
|
return $expiresAt !== null && $expiresAt->isPast();
|
|
}
|
|
|
|
public function isAccepted(): bool
|
|
{
|
|
return $this->accepted_at !== null;
|
|
}
|
|
}
|