PHP code example of shipu / filament-boring-avatars

1. Go to this page and download the library: Download shipu/filament-boring-avatars library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

shipu / filament-boring-avatars example snippets


return [
    // default source url for Boring Avatars API
    'url' => 'https://source.boringavatars.com',

    // variants = marble (default), beam, pixel, sunset, ring, bauhaus
    'variant' => 'marble',

    // size in px
    'size' => '40',

    // array of colors to use
    'colors' => ['#264653','#2a9d8f','#e9c46a','#f4a261','#e76f51'],
];

/*
|--------------------------------------------------------------------------
| Default Avatar Provider
|--------------------------------------------------------------------------
|
| This is the service that will be used to retrieve default avatars if one
| has not been uploaded.
|
*/

'default_avatar_provider' => Cmdinglasan\FilamentBoringAvatars\AvatarProviders\UiAvatarsProvider::class,



namespace App\Models;

use Cmdinglasan\FilamentBoringAvatars\Traits\HasAvatarUrl;

class User
{
    use HasAvatarUrl;
}

// Example for getAttribute:
public function getNameAttribute()
{
    return $this->first_name . ' ' . $this->last_name;
}

// Example using accessor
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    /**
     * Get the user's name
     *
     * @return Attribute
     */
    protected function name(): Attribute
    {
        return Attribute::make(
            get: fn () => $this->first_name . ' ' . $this->last_name,
        );
    }
}

$user = User::find(1)->avatarUrl;
bash
php artisan vendor:publish --tag="filament-boring-avatars-config"