generated from thegrind/laravel-dockerized
36 lines
676 B
PHP
36 lines
676 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Invitation extends Model
|
|
{
|
|
protected $guarded = ['id'];
|
|
protected $casts = [
|
|
'expires_at' => 'datetime',
|
|
'accepted_at' => 'datetime'
|
|
];
|
|
|
|
public function status(): string
|
|
{
|
|
return !empty($this->accepted_at) ? 'accepted' : 'pending';
|
|
}
|
|
|
|
public function isPending(): bool
|
|
{
|
|
return empty($this->accepted_at);
|
|
}
|
|
|
|
public function accept(): void
|
|
{
|
|
$this->accepted_at = now();
|
|
$this->save();
|
|
}
|
|
|
|
public function getInviteUrl(): string
|
|
{
|
|
return route('register', ['code' => $this->code]);
|
|
}
|
|
}
|