Users can now upload an avatar from Profile settings.

This commit is contained in:
2026-05-16 04:00:06 +03:30
parent f46f32aa4c
commit 61b4cf9252
13 changed files with 274 additions and 19 deletions

View File

@@ -6,15 +6,17 @@ namespace App\Models;
use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Hidden;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Storage;
use Laravel\Fortify\TwoFactorAuthenticatable;
#[Fillable(['name', 'email', 'password', 'is_admin', 'can_create_channel', 'suspended_at'])]
#[Hidden(['password', 'two_factor_secret', 'two_factor_recovery_codes', 'remember_token'])]
#[Fillable(['name', 'email', 'password', 'avatar_path', 'is_admin', 'can_create_channel', 'suspended_at'])]
#[Hidden(['password', 'avatar_path', 'two_factor_secret', 'two_factor_recovery_codes', 'remember_token'])]
class User extends Authenticatable
{
/** @use HasFactory<UserFactory> */
@@ -24,6 +26,10 @@ class User extends Authenticatable
'can_create_channel' => false,
];
protected $appends = [
'avatar',
];
/**
* Get the attributes that should be cast.
*
@@ -60,4 +66,12 @@ class User extends Authenticatable
{
return $this->can_create_channel || PlatformSetting::current()->channel_creation_open;
}
/**
* @return Attribute<string|null, never>
*/
protected function avatar(): Attribute
{
return Attribute::get(fn (): ?string => $this->avatar_path ? Storage::url($this->avatar_path) : null);
}
}