mirror of https://github.com/pixelfed/pixelfed
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.1 KiB
PHP
51 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* @method static Builder|AdminInvite whereInviteCode(string $value)
|
|
*/
|
|
class AdminInvite extends Model
|
|
{
|
|
protected $guarded = [];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'used_by' => 'array',
|
|
'expires_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (AdminInvite $invite) {
|
|
$invite->invite_code = (string) Str::uuid().Str::random(random_int(1, 6));
|
|
});
|
|
}
|
|
|
|
public function url(): string
|
|
{
|
|
return url('/auth/invite/a/'.$this->invite_code);
|
|
}
|
|
|
|
public function isActive(): bool
|
|
{
|
|
return $this->hasUsesRemaining() && ! $this->hasExpired();
|
|
}
|
|
|
|
public function hasExpired(): bool
|
|
{
|
|
return $this->expires_at?->isPast() ?? false;
|
|
}
|
|
|
|
public function hasUsesRemaining(): bool
|
|
{
|
|
return $this->max_uses === 0 || is_null($this->max_uses) || $this->uses < $this->max_uses;
|
|
}
|
|
}
|