#48 - user avatars using ui-avatars.com
This commit is contained in:
@@ -13,6 +13,7 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Rackbeat\UIAvatars\HasAvatar;
|
||||
use Toby\Domain\Enums\EmploymentForm;
|
||||
use Toby\Domain\Enums\Role;
|
||||
|
||||
@@ -35,6 +36,7 @@ class User extends Authenticatable
|
||||
use HasFactory;
|
||||
use Notifiable;
|
||||
use SoftDeletes;
|
||||
use HasAvatar;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
@@ -80,11 +82,13 @@ class User extends Authenticatable
|
||||
->orWhere("email", "ILIKE", $text);
|
||||
}
|
||||
|
||||
public function saveAvatar(string $path): void
|
||||
public function getAvatar(): string
|
||||
{
|
||||
$this->avatar = $path;
|
||||
$colors = config("colors");
|
||||
|
||||
$this->save();
|
||||
return $this->getAvatarGenerator()
|
||||
->backgroundColor($colors[strlen($this->fullname) % count($colors)])
|
||||
->image();
|
||||
}
|
||||
|
||||
public function getFullNameAttribute(): string
|
||||
@@ -97,6 +101,11 @@ class User extends Authenticatable
|
||||
return $this->role === $role;
|
||||
}
|
||||
|
||||
protected function getAvatarNameKey(): string
|
||||
{
|
||||
return "fullName";
|
||||
}
|
||||
|
||||
protected static function newFactory(): UserFactory
|
||||
{
|
||||
return UserFactory::new();
|
||||
|
||||
Reference in New Issue
Block a user