64 lines
1.3 KiB
PHP
64 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* @property string $id
|
|
* @property string $space_id
|
|
* @property ?string $invited_by_id
|
|
* @property string $email
|
|
* @property string $role
|
|
* @property string $token
|
|
* @property ?Carbon $expires_at
|
|
* @property ?Carbon $accepted_at
|
|
*/
|
|
class SpaceInvitation extends Model
|
|
{
|
|
use HasUuids;
|
|
|
|
protected $fillable = [
|
|
'space_id',
|
|
'invited_by_id',
|
|
'email',
|
|
'role',
|
|
'token',
|
|
'expires_at',
|
|
'accepted_at',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'expires_at' => 'datetime',
|
|
'accepted_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
/** @return BelongsTo<Space, $this> */
|
|
public function space(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Space::class);
|
|
}
|
|
|
|
/** @return BelongsTo<User, $this> */
|
|
public function invitedBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'invited_by_id');
|
|
}
|
|
|
|
public function isExpired(): bool
|
|
{
|
|
return $this->expires_at !== null && $this->expires_at->isPast();
|
|
}
|
|
|
|
public function isAccepted(): bool
|
|
{
|
|
return $this->accepted_at !== null;
|
|
}
|
|
}
|