承接 laravel-enso/avatarmanager 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

laravel-enso/avatarmanager

最新稳定版本:4.5.7

Composer 安装命令:

composer require laravel-enso/avatarmanager

包简介

User Avatar manager dependency for Laravel Enso

README 文档

README

License Stable Downloads PHP Issues Merge Requests

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 a locally generated Laravolt avatar when it does not.

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.

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

Features

  • Adds a one-to-one avatar relation to LaravelEnso\Users\Models\User through 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 generated Laravolt image when no Gravatar exists.
  • 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:allow_svg|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/avatars
  • PATCH /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_id
  • file_id
  • url

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

Depends On

Required Enso packages:

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!

统计信息

  • 总下载量: 16.33k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 3
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-06-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固