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.
pixelfed/app/Models/AdminInvite.php

47 lines
1008 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
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 = 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;
}
}