diff --git a/config/config.php b/config/config.php
index 091f61473..129acabd7 100644
--- a/config/config.php
+++ b/config/config.php
@@ -101,6 +101,7 @@
// Name of the login and password attributes of the User Model.
'login_attribute' => 'email',
'password_attribute' => 'password',
+ 'avatar_attribute' => 'avatar',
'rate_limiting' => [
'enabled' => true,
diff --git a/demo/app/Models/User.php b/demo/app/Models/User.php
index 47a047ab8..ec161bcd4 100644
--- a/demo/app/Models/User.php
+++ b/demo/app/Models/User.php
@@ -2,6 +2,7 @@
namespace App\Models;
+use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphOne;
@@ -38,6 +39,13 @@ public function avatar(): MorphOne
->where('model_key', 'avatar');
}
+ public function avatarUrl(): Attribute
+ {
+ return Attribute::make(
+ get: fn () => $this->avatar?->thumbnail(500),
+ );
+ }
+
public function getDefaultAttributesFor(string $attribute): array
{
return in_array($attribute, ['avatar'])
diff --git a/demo/app/Providers/DemoSharpServiceProvider.php b/demo/app/Providers/DemoSharpServiceProvider.php
index 464f0919e..3c4c6a7d5 100644
--- a/demo/app/Providers/DemoSharpServiceProvider.php
+++ b/demo/app/Providers/DemoSharpServiceProvider.php
@@ -42,6 +42,7 @@ protected function configureSharp(SharpConfigBuilder $config): void
->setAuthCustomGuard('web')
->setLoginAttributes('email', 'password')
->setUserDisplayAttribute('name')
+ ->setUserAvatarAttribute('avatar_url')
->enable2faCustom(Demo2faNotificationHandler::class)
->enableLoginRateLimiting(maxAttempts: 3)
->suggestRememberMeOnLoginForm()
diff --git a/docs/guide/authentication.md b/docs/guide/authentication.md
index d6d6f6640..0b9498c9c 100644
--- a/docs/guide/authentication.md
+++ b/docs/guide/authentication.md
@@ -14,12 +14,14 @@ class SharpServiceProvider extends SharpAppServiceProvider
$config
->setLoginAttributes('login', 'pwd')
->setUserDisplayAttribute('last_name')
+ ->setUserAvatarAttribute('avatar_url')
// [...]
}
}
```
-The `setUserDisplayAttribute()` is useful to display the user's name in the Sharp UI. Default is `name`.
+- The `setUserDisplayAttribute()` is useful to display the user's name in the Sharp UI. Default is `name`.
+- The `setUserAvatarAttribute()` is useful to display the user's avatar in the Sharp UI. Default is `avatar`, when the attribute returns null, the default user icon is displayed instead.
## Login form
diff --git a/resources/js/Layouts/Layout.vue b/resources/js/Layouts/Layout.vue
index 533cc187b..71ca2fadd 100644
--- a/resources/js/Layouts/Layout.vue
+++ b/resources/js/Layouts/Layout.vue
@@ -206,7 +206,10 @@
class="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
>
-