|null $used_by * @property int|null $admin_user_id * @property Carbon|null $created_at * @property Carbon|null $updated_at * * @method static Builder|AdminInvite newModelQuery() * @method static Builder|AdminInvite newQuery() * @method static Builder|AdminInvite query() * @method static Builder|AdminInvite whereAdminUserId($value) * @method static Builder|AdminInvite whereCreatedAt($value) * @method static Builder|AdminInvite whereDescription($value) * @method static Builder|AdminInvite whereExpiresAt($value) * @method static Builder|AdminInvite whereId($value) * @method static Builder|AdminInvite whereInviteCode($value) * @method static Builder|AdminInvite whereMaxUses($value) * @method static Builder|AdminInvite whereMessage($value) * @method static Builder|AdminInvite whereName($value) * @method static Builder|AdminInvite whereSkipEmailVerification($value) * @method static Builder|AdminInvite whereUpdatedAt($value) * @method static Builder|AdminInvite whereUsedBy($value) * @method static Builder|AdminInvite whereUses($value) * * @mixin \Eloquent */ 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; } }