laravel-enso / avatarmanager
User Avatar manager dependency for Laravel Enso
Requires
- laravel-enso/core: ^12.0
- laravel-enso/dynamic-methods: ^4.0
- laravel-enso/files: ^5.7
- laravel-enso/image-transformer: ^2.5.6
- laravel-enso/migrator: ^2.0
- laravel-enso/users: ^2.8
- laravolt/avatar: ^6.5
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
- dev-master
- 4.6.0
- 4.5.9
- 4.5.8
- 4.5.7
- 4.5.6
- 4.5.5
- 4.5.4
- 4.5.3
- 4.5.2
- 4.5.1
- 4.5.0
- 4.4.0
- 4.3.0
- 4.2.1
- 4.2.0
- 4.1.1
- 4.1.0
- 4.0.9
- 4.0.8
- 4.0.7
- 4.0.6
- 4.0.5
- 4.0.4
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0.0
- 3.2.8
- 3.2.7
- 3.2.6
- 3.2.5
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.5.11
- 2.5.10
- 2.5.9
- 2.5.8
- 2.5.7
- 2.5.6
- 2.5.5
- 2.5.4
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.7
- 2.4.6
- 2.4.5
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.16
- 2.3.15
- 2.3.14
- 2.3.13
- 2.3.12
- 2.3.11
- 2.3.10
- 2.3.9
- 2.3.8
- 2.3.7
- 2.3.6
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.7
- 2.2.6
- 2.2.5
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.31
- 2.1.30
- 2.1.29
- 2.1.28
- 2.1.27
- 2.1.26
- 2.1.25
- 2.1.24
- 2.1.23
- 2.1.22
- 2.1.21
- 2.1.20
- 2.1.19
- 2.1.18
- 2.1.17
- 2.1.16
- 2.1.15
- 2.1.14
- 2.1.13
- 2.1.12
- 2.1.11
- 2.1.10
- 2.1.9
- 2.1.8
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.16
- 1.1.15
- 1.1.14
- 1.1.13
- 1.1.12
- 1.1.11
- 1.1.10
- 1.1.9
- 1.1.8
- 1.1.7
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- dev-upgrade/laravel13-core12
- dev-feature/ensoV8
- dev-feature/laravel12
- dev-upgrade/larave11MigrationChange
- dev-upgrade/enso6-dr
- dev-upgrade/enso6
- dev-feature/dropSuffix
- dev-fixes/obeserver
- dev-hotfix/tests
This package is auto-updated.
Last update: 2026-10-15 13:07:13 UTC
README
Description
Avatars is Laravel Enso's user avatar package.
It attaches one avatar record to each user, exposes authenticated endpoints for viewing, uploading, and regenerating avatars, and integrates with Enso's file pipeline so custom uploads are stored and transformed consistently.
The package also generates default avatars automatically. It prefers Gravatar when a public image exists for the user's email address and falls back to an SVG rendered on demand with Laravolt when it does not. SVG fallbacks do not create image files or file records.
The frontend integration lives primarily in the Enso user profile experience and reusable avatar components from @enso-ui/users.
Installation
This package comes pre-installed in Laravel Enso applications that support user profile avatars.
For standalone installation in an Enso-based application:
composer require laravel-enso/avatars
The package auto-registers its service providers, loads migrations, registers API routes, observes user creation, and exposes the avatar generation command.
The current release uses Laravolt Avatar 6.5 and Laravel Enso Image Transformer 2.5.6, both backed by Intervention Image 4.
Run the migrations after installation:
php artisan migrate
If you need the package storage scaffolding, publish it with:
php artisan vendor:publish --tag=avatars-storage
Publish the avatar configuration with:
php artisan vendor:publish --tag=avatars-config
Set enso.avatars.useGravatar to false to use SVG fallbacks without probing Gravatar. The option defaults to true.
Set enso.avatars.background to change the shared SVG background color (default: #64748b). The legacy laravolt.avatar.backgrounds palette is ignored for these fallbacks. Initials reflect the user's current name and are escaped for XML.
Features
- Adds a one-to-one avatar relation to
LaravelEnso\Users\Models\Userthrough dynamic methods. - Adds a
generateAvatar()dynamic method to users for regenerating their default avatar. - Generates a default avatar automatically whenever a new user is created.
- Prefers Gravatar and falls back to a dynamic SVG when no Gravatar exists.
- Uses one configurable background color for SVG fallbacks without storing generated images.
- Stores uploaded avatar files through
laravel-enso/files. - Deletes the previously attached file when an avatar is replaced.
- Enforces square image uploads.
- Exposes avatar display, upload, and regenerate endpoints under the core API namespace.
- Registers permissions and authorization for avatar operations.
Usage
The package binds an avatar() relation and generateAvatar() method to the Enso user model:
$user->avatar; $user->generateAvatar();
Store a custom uploaded avatar for the authenticated user:
use Illuminate\Http\UploadedFile; $request->validate([ 'avatar' => 'required|image|dimensions:ratio=1', ]); $request->user()->avatar->store( UploadedFile::fake()->image('avatar.png', 512, 512), );
Regenerate the default avatar:
$request->user()->generateAvatar();
Display an avatar in the browser by hitting the show endpoint:
route('core.avatars.show', $user->avatar->id);
::: warning Note The package is designed to work with a single avatar per user. When you regenerate or upload a new avatar, the previously attached file is removed automatically. :::
API
Routes
All package routes are registered under:
- prefix:
api/core/avatars - name prefix:
core.avatars. - middleware:
api,auth,core
Endpoints:
POST /api/core/avatarsPATCH /api/core/avatars/{avatar}GET /api/core/avatars/{avatar}
Authorization
LaravelEnso\Avatars\Policies\AvatarPolicy
- superiors may manage any avatar
- regular users may update only their own avatar
- impersonating users may not update avatars
Model
LaravelEnso\Avatars\Models\Avatar
Persisted fields:
user_idfile_idurl
Relationships:
user()file()
Useful methods:
store(UploadedFile $uploadedFile)extensions()mimeTypes()imageWidth()imageHeight()
Dynamic User Integration
Dynamic additions on LaravelEnso\Users\Models\User:
avatar()generateAvatar()
Command
Generate missing avatars for users without one:
php artisan enso:avatars:generate
Upgrading to 4.6
Update the package, then run the standard Enso upgrade command:
composer update laravel-enso/avatars php artisan enso:upgrade
The LegacyAvatars upgrade replaces legacy candidates with SVG fallbacks and permanently deletes their file records and stored images. It selects avatars without a remote URL whose attached file belongs to the avatar type, has MIME type image/jpeg, and has the exact original name avatar.<user_id>.jpg.
This naming convention is a heuristic: an uploaded JPEG with that exact name is also deleted. Review candidates and retain a backup before running the upgrade if such uploads may exist. Other uploads and Gravatar URLs are preserved. No file-size or created_by threshold is used.
The upgrade is repeatable and also handles missing physical files. A storage deletion returning false does not stop the upgrade; the avatar association and file record are still removed, so that physical file may remain orphaned.
Existing file-backed avatars continue to display until replaced or processed by the upgrade. New users and explicit default-avatar regeneration use Gravatar or SVG immediately. Both file_id and url are null for an SVG fallback; the avatar record and show endpoint remain available.
Depends On
Required Enso packages:
laravel-enso/core↗laravel-enso/dynamic-methods↗laravel-enso/files↗laravel-enso/image-transformer↗laravel-enso/migrator↗laravel-enso/users↗
Companion frontend package:
External dependency:
Contributions
are welcome. Pull requests are great, but issues are good too.
Thank you to all the people who already contributed to Enso!