forxer / laravel-gravatar
A library providing easy gravatar integration in a Laravel project.
Installs: 30 754
Dependents: 1
Suggesters: 0
Security: 0
Stars: 41
Watchers: 2
Forks: 10
Open Issues: 0
pkg:composer/forxer/laravel-gravatar
Requires
- php: ^8.4
- forxer/gravatar: ^6.0
- laravel/framework: ^12.0
Requires (Dev)
- driftingly/rector-laravel: ^2.1.3
- laravel/pint: ^1.25.1
- rector/rector: ^2.2.8
README
Gravatar for Laravel
This package provides an easy Gravatar integration in a Laravel project.
use Gravatar\Enum\DefaultImage; use Gravatar\Enum\Extension; // Simple usage $avatar = gravatar('email@example.com') ->size(120) ->defaultImage('robohash') ->extension('jpg'); echo $avatar; // With type-safe enums $avatar = gravatar('email@example.com') ->size(120) ->defaultImage(DefaultImage::ROBOHASH) ->extension(Extension::JPG); // With fluent shorthand methods $avatar = gravatar('email@example.com') ->size(120) ->extensionJpg() ->defaultImageRobohash();
About this package
This Laravel package is built on top of the framework-agnostic forxer/gravatar library. It extends the base functionality by adding:
- Laravel-specific features: Service providers, facades, helper functions (
gravatar()andgravatar_profile()), and configuration - Extended classes:
LaravelGravatar\ImageextendsGravatar\Image, andLaravelGravatar\ProfileextendsGravatar\Profile - Additional Laravel integrations: Eloquent casts, preset configurations, and base64 conversion with Laravel's HTTP client
- Full support for PHP 8.4 features: Property hooks, type-safe enums, and fluent shorthand methods from the parent library
All the core Gravatar functionality from the parent library is available in this package.
Documentation
Complete documentation is available in the docs directory:
- Overview - Introduction and quick start
- Installation - Install and configure
- Usage - Helpers, facades, and dependency injection
- Parameters - All available Gravatar parameters
- Enums - Type-safe enums and fluent methods
- Configuration - Configure the package
- Presets - Complete guide to preset configurations
- Casts - Eloquent model integration
- Advanced Features - Base64 conversion, copying, and more
Requirements
- PHP 8.4+
- Laravel 12.0+
For earlier versions:
- Version 4.x - PHP 8.2+ and Laravel 10.0+
- Version 2.x - PHP 8.0+ and Laravel 8.0+
- Version 1.x - Older versions
Quick Installation
composer require forxer/laravel-gravatar
The service provider is automatically registered via package discovery.
Quick Start
// Simple usage with helper <img src="{{ gravatar($user->email) }}" alt="Avatar"> // With configuration $avatar = gravatar('user@example.com') ->size(120) ->extensionWebp() ->defaultImageRobohash(); // Using presets $avatar = gravatar($user->email, 'small'); // With Eloquent casts class User extends Model { protected $casts = [ 'email' => GravatarImage::class.':medium', ]; } // In Blade <img src="{{ $user->email }}" alt="Avatar">
Key Features
- Helper functions -
gravatar()andgravatar_profile()for quick access - Facade support -
Gravatar::image()andGravatar::profile() - Eloquent casts - Seamless model integration
- Preset configurations - Define reusable avatar settings with automatic validation
- Enum-based validation - Preset values validated against type-safe enums at runtime
- Base64 conversion - Convert avatars to data URLs
- PHP 8.4 property hooks - Direct property access with validation
- Type-safe enums -
Rating,Extension,DefaultImage,ProfileFormat - Fluent shorthand methods -
extensionWebp(),ratingPg(),defaultImageRobohash()
Version History
See CHANGELOG.md for all changes.
Upgrading
See UPGRADE.md for upgrade instructions between major versions.
License
This package is open-source software licensed under the MIT license.