/
evo
/
docviz
Обзор
Документация
Войти
/
evo
/
docviz
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
app/Models/User.php
137 строк
3 KB
evo
UI updates, deployment prep, and code highlighting fix
08 фев 2026, 12:17
Верифицирован
08 фев 2026, 12:17
2c0897e
Код
Авторство
О чём код?
<?php namespace App\Models; // use Illuminate\Contracts\Auth\MustVerifyEmail; use App\Models\Traits\HasUserStatus; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; class User extends Authenticatable { /** @use HasFactory<\Database\Factories\UserFactory> */ use HasFactory, Notifiable, HasUserStatus; /** * The attributes that are mass assignable. * * @var list<string> */ protected $fillable = [ 'name', 'alias', 'email', 'password', 'about', 'avatar', 'gender', 'birth_date', 'role', 'previous_role', 'banned_until', 'last_activity_at', 'show_email', 'show_age', 'theme', ]; /** * The attributes that should be hidden for serialization. * * @var list<string> */ protected $hidden = [ 'password', 'remember_token', ]; /** * Get the attributes that should be cast. * * @return array<string, string> */ protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', 'banned_until' => 'datetime', 'birth_date' => 'date', 'last_activity_at' => 'datetime', ]; } /** * Get the avatar URL - either uploaded or Gravatar. */ public function getAvatarUrlAttribute(): string { if ($this->avatar) { return asset('storage/' . $this->avatar); } // Gravatar с параметрами: identicon как fallback, размер 256px $email = strtolower(trim($this->email)); $hash = md5($email); return "https://www.gravatar.com/avatar/{$hash}?d=identicon&s=256"; } /** * Calculate age from birth_date. * Returns null if birth_date is not set. */ public function getAgeAttribute(): ?int { if (!$this->birth_date) { return null; } return $this->birth_date->age; } public function media() { return $this->hasMany(Media::class, 'user_id'); } public function createdCategories() { return $this->hasMany(DocCategory::class, 'created_by'); } public function createdPages() { return $this->hasMany(DocPage::class, 'created_by'); } public function activity() { return $this->hasOne(\App\Modules\Messaging\Models\UserActivity::class); } public function sentMessages() { return $this->hasMany(\App\Modules\Messaging\Models\Message::class, 'from_user_id'); } public function receivedMessages() { return $this->hasMany(\App\Modules\Messaging\Models\Message::class, 'to_user_id'); } public function appeals() { return $this->hasMany(Appeal::class); } public function latestAppeal() { return $this->hasOne(Appeal::class)->latestOfMany(); } public function isOnline(): bool { return app(\App\Services\UserPresenceService::class)->isOnline($this); } }