Upload beautify
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
@@ -55,6 +56,11 @@ class User extends Authenticatable
|
||||
return $this->hasMany(Artwork::class);
|
||||
}
|
||||
|
||||
public function profile(): HasOne
|
||||
{
|
||||
return $this->hasOne(UserProfile::class, 'user_id');
|
||||
}
|
||||
|
||||
public function hasRole(string $role): bool
|
||||
{
|
||||
return strtolower((string) ($this->role ?? '')) === strtolower($role);
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use App\Support\AvatarUrl;
|
||||
|
||||
class UserProfile extends Model
|
||||
{
|
||||
@@ -18,7 +18,7 @@ class UserProfile extends Model
|
||||
'about',
|
||||
'signature',
|
||||
'description',
|
||||
'avatar',
|
||||
'avatar_legacy',
|
||||
'avatar_hash',
|
||||
'avatar_mime',
|
||||
'avatar_updated_at',
|
||||
@@ -43,27 +43,12 @@ class UserProfile extends Model
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a public URL for the avatar when stored on the `public` disk under `avatars/`.
|
||||
*/
|
||||
public function getAvatarUrlAttribute(): ?string
|
||||
{
|
||||
if (empty($this->avatar)) {
|
||||
if (empty($this->user_id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// If the stored value already looks like a full URL, return it.
|
||||
if (preg_match('#^https?://#i', $this->avatar)) {
|
||||
return $this->avatar;
|
||||
}
|
||||
|
||||
// Prefer `public` disk and avatars folder.
|
||||
$path = 'avatars/' . ltrim($this->avatar, '/');
|
||||
if (Storage::disk('public')->exists($path)) {
|
||||
return Storage::disk('public')->url($path);
|
||||
}
|
||||
|
||||
// Fallback: return null if not found
|
||||
return null;
|
||||
return AvatarUrl::forUser((int) $this->user_id, $this->avatar_hash, 128);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user