*/ use HasApiTokens, HasFactory, Notifiable; /** * Role granted to platform administrators. * * @var string */ public const ROLE_ADMIN = 'admin'; /** * Role granted to regular citizens of the virtual city. * * @var string */ public const ROLE_USER = 'user'; /** * Stores owned by this user. * * @return HasMany */ public function stores(): HasMany { return $this->hasMany(Store::class, 'owner_id'); } /** * Legal consents recorded for this user. * * @return HasMany */ public function consents(): HasMany { return $this->hasMany(UserConsent::class); } /** * Legal documents this user has accepted. * * @return BelongsToMany */ public function acceptedDocuments(): BelongsToMany { return $this->belongsToMany(LegalDocument::class, 'user_consents') ->withPivot(['accepted_at', 'ip_address', 'user_agent', 'source']) ->withTimestamps(); } /** * Determine whether the user holds administrator privileges. */ public function isAdmin(): bool { return $this->role === self::ROLE_ADMIN; } /** * Check whether the user accepted every current legal document version. */ public function hasAcceptedCurrentTerms(): bool { $currentIds = LegalDocument::query()->where('is_current', true)->pluck('id'); if ($currentIds->isEmpty()) { return true; } $acceptedIds = $this->consents()->pluck('legal_document_id'); return $currentIds->diff($acceptedIds)->isEmpty(); } /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'last_login_at' => 'datetime', 'password' => 'hashed', 'is_active' => 'boolean', ]; } }