PHPackages                             danjamesmills/initials-avatar-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. danjamesmills/initials-avatar-generator

ActiveLibrary

danjamesmills/initials-avatar-generator
=======================================

2.0.1(1y ago)241MITPHPPHP ^7.3|^8.0CI passing

Since Oct 18Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/DanJamesMills/initials-avatar-generator)[ Packagist](https://packagist.org/packages/danjamesmills/initials-avatar-generator)[ Docs](https://github.com/danjamesmills/initials-avatar-generator)[ RSS](/packages/danjamesmills-initials-avatar-generator/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (5)Versions (4)Used By (0)

Intro
=====

[](#intro)

[![Latest Version on Packagist](https://camo.githubusercontent.com/af92aabef87486cb394b78906ea8d360f71ca00b17f0d90843e2842a3aa27475/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64616e6a616d65736d696c6c732f696e697469616c732d6176617461722d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/danjamesmills/initials-avatar-generator)[![Total Downloads](https://camo.githubusercontent.com/dce46f439e64f7e6666d7d90805835fee1f7d1a5f6eafcd2279795d72321e70c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64616e6a616d65736d696c6c732f696e697469616c732d6176617461722d67656e657261746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/danjamesmills/initials-avatar-generator)[![GitHub Actions](https://github.com/danjamesmills/initials-avatar-generator/actions/workflows/main.yml/badge.svg)](https://github.com/danjamesmills/initials-avatar-generator/actions/workflows/main.yml/badge.svg)

Introducing the Laravel Avatar package, a powerful tool for generating unique avatar images for any model in your Laravel application. This package allows you to easily create unique avatar images based on fields you specify for your models, such as name, email, or any other field. With this package, you can easily add avatar functionality to your application and ensure that each user or model has a distinct and personalised avatar image. It's also configurable to use different image generation libraries, so you can pick the one that fits your project best. With a simple and intuitive API, you can easily generate avatars for any model in your application, saving you time and effort. The Laravel Avatar package makes it easy to add personalized avatars to your application, enhance the user experience and make your app look more professional.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require danjamesmills/initials-avatar-generator
```

Publish Config (optional)
-------------------------

[](#publish-config-optional)

You should publish the migration and the config/initials-avatar-generator.php config file with:

```
php artisan vendor:publish --provider="DanJamesMills\InitialsAvatarGenerator\InitialsAvatarGeneratorServiceProvider"
```

Run the migrations: After the config and migration have been published and configured, you can create the tables for this package by running:

```
php artisan migrate
```

Publicly Accessible Storage Path
--------------------------------

[](#publicly-accessible-storage-path)

In the config/initials-avatar-generator.php we have used the following path below for storage of avatar images, feel free to change this.

```
'storage_path' => storage_path('app/public/avatars/'),
```

If your using the above don't forget to link storage and public paths from console and create 'avatars' folder.

```
mkdir storage/app/public/avatars
```

```
php artisan storage:link
```

Basic Usage
-----------

[](#basic-usage)

First, add the DanJamesMills\\InitialsAvatarGenerator\\Traits\\HasAvatar trait to your User model(s):

```
use Illuminate\Foundation\Auth\User as Authenticatable;
use DanJamesMills\InitialsAvatarGenerator\Traits\HasAvatar;

class User extends Authenticatable
{
    use HasAvatar;

    // ...
}
```

### Defining An Accessor

[](#defining-an-accessor)

```
use Illuminate\Foundation\Auth\User as Authenticatable;
use DanJamesMills\InitialsAvatarGenerator\Traits\HasAvatar;
use Illuminate\Database\Eloquent\Casts\Attribute;

class User extends Authenticatable
{
    /**
     * Get the user's avatar.
     *
     * @return \Illuminate\Database\Eloquent\Casts\Attribute
     */
    protected function avatar(): Attribute
    {
        return Attribute::make(
            get: fn ($value) => url("/storage/avatars/{$value}"),
        );
    }
}
```

### Define Model Avatar Fields

[](#define-model-avatar-fields)

```
use Illuminate\Foundation\Auth\User as Authenticatable;
use DanJamesMills\InitialsAvatarGenerator\Traits\HasAvatar;

class User extends Authenticatable
{
    /**
     * Used to define the fields of which initials avatar
     * generator will create initials from.
     *
     * @return string
     */
    protected function defineNameInitialsAvatarGenerator(): string
    {
        return $this->name;
    }
}
```

If you have used a different column name from the default migration name of 'avatar', you must define this new column name on the model.

```
use Illuminate\Foundation\Auth\User as Authenticatable;
use DanJamesMills\InitialsAvatarGenerator\Traits\HasAvatar;

class User extends Authenticatable
{
    /**
     * Used to define the column field name of which
     * you want to save avatar image to.
     *
     * @return string
     */
    protected function defineAvatarColumnName(): string
    {
        return 'avatarColumnName';
    }
}
```

### Generating Avatar

[](#generating-avatar)

If your model has no avatar set, you can generate one below.

```
$user = User::findOrFail(4);

$user->generateAvatarAndSet();
$user->save();

return "";
```

If you update the value of the avatar field i.e user's name, an avatar will be automatically generated and saved for you.

```
$user = User::findOrFail(4);

$user->name = 'John Doe'; // changed from Dan Doe
$user->save();

return "";
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Danny Mills](https://github.com/danjamesmills)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance47

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~530 days

Total

3

Last Release

604d ago

Major Versions

1.0.0 → 2.0.02024-04-25

PHP version history (2 changes)1.0.0PHP ^7.4|^8.0

2.0.0PHP ^7.3|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9045fbac486221010088d39798a6a3972091db9a0d40a3c44179ee23a01e743c?d=identicon)[danny620](/maintainers/danny620)

---

Top Contributors

[![DanJamesMills](https://avatars.githubusercontent.com/u/2931604?v=4)](https://github.com/DanJamesMills "DanJamesMills (49 commits)")

---

Tags

danjamesmillsinitials-avatar-generator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/danjamesmills-initials-avatar-generator/health.svg)

```
[![Health](https://phpackages.com/badges/danjamesmills-initials-avatar-generator/health.svg)](https://phpackages.com/packages/danjamesmills-initials-avatar-generator)
```

###  Alternatives

[laravolt/avatar

Turn name, email, and any other string into initial-based avatar or gravatar.

2.0k5.4M31](/packages/laravolt-avatar)[unisharp/laravel-filemanager

A file upload/editor intended for use with Laravel 5 to 10 and CKEditor / TinyMCE

2.2k3.3M73](/packages/unisharp-laravel-filemanager)[intervention/image-laravel

Laravel Integration of Intervention Image

1496.5M100](/packages/intervention-image-laravel)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

510496.0k22](/packages/bkwld-croppa)[beyondcode/laravel-favicon

Create dynamic favicons based on your environment settings.

37345.5k](/packages/beyondcode-laravel-favicon)[flarum/core

Delightfully simple forum software.

211.3M1.9k](/packages/flarum-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
