Add ability to set custom avatar
This commit is contained in:
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
use Laravelista\Comments\Commenter;
|
||||
|
||||
@@ -94,4 +95,22 @@ class User extends Authenticatable
|
||||
{
|
||||
return DB::table('comments')->where('commenter_id', $this->id)->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user avatar image url.
|
||||
*/
|
||||
public function getAvatar(): string
|
||||
{
|
||||
if ($this->discord_id && $this->discord_avatar && !$this->avatar)
|
||||
{
|
||||
return "https://external-content.duckduckgo.com/iu/?u=https://cdn.discordapp.com/avatars/{$this->discord_id}/{$this->discord_avatar}.webp";
|
||||
}
|
||||
|
||||
if ($this->avatar)
|
||||
{
|
||||
return Storage::url($this->avatar);
|
||||
}
|
||||
|
||||
return asset('images/default-avatar.webp');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user