PHP code example of forxer / laravel-gravatar

1. Go to this page and download the library: Download forxer/laravel-gravatar 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/ */

    

forxer / laravel-gravatar example snippets


$avatar = gravatar('[email protected]')
    ->size(120)
    ->defaultImage('robohash')
    ->extension('jpg');
//...
echo $avatar;

$gravatar = gravatar();
// LaravelGravatar\Gravatar instance

$avatar = gravatar('[email protected]');
// LaravelGravatar\Image instance

$avatar = gravatar()->image('[email protected]');
// LaravelGravatar\Image instance

$avatar = gravatar()->avatar('[email protected]');
// LaravelGravatar\Image instance

$profile = gravatar()->profile('[email protected]');
// LaravelGravatar\Profile instance

use LaravelGravatar\Facades\Gravatar;

$gravatar = Gravatar::create();
// LaravelGravatar\Gravatar instance

$avatar = Gravatar::image('[email protected]');
// LaravelGravatar\Image instance

$avatar = Gravatar::avatar('[email protected]');
// LaravelGravatar\Image instance

$profile = Gravatar::profile('[email protected]');
// LaravelGravatar\Profile instance

use App\Models\User;
use LaravelGravatar\Gravatar as Gravatar;

class UserController
{
    public function show(User $user, Gravatar $gravatar)
    {
        $avatar = $gravatar->avatar($user->email);

        $profile = $gravatar->profile($user->email);
    }
}

$gravatar = gravatar('[email protected]');
$gravatarUrl = $gravatar->url();

$gravatar = Gravatar::avatar('[email protected]');
$gravatarUrl = $gravatar->url();

// pass it as argument of the helper
$gravatarImage = gravatar($email);

// or use the `setEmail()` method
$gravatarImage = gravatar();
$gravatarImage->setEmail($email);

// or the `email()` helper method
$gravatarImage = gravatar();
$gravatarImage->email($email);

// use the `setSize()` method
$gravatarImage = gravatar($email);
$gravatarImage->setSize(120);

// or the `size()` helper method
$gravatarImage = gravatar($email);
$gravatarImage->size(120);

// or its alias `s()` (as in the generated query string)
$gravatarImage = gravatar($email);
$gravatarImage->s(120);

// use the `setDefaultImage()` method
$gravatarImage = gravatar($email);
$gravatarImage->setDefaultImage('mp');

// or the `defaultImage()` helper method
$gravatarImage = gravatar($email);
$gravatarImage->defaultImage('mp');

// or its alias `d()` (as in the generated query string)
$gravatarImage = gravatar($email);
$gravatarImage->d('mp');

// use the `setMaxRating()` method
$gravatarImage = gravatar($email);
$gravatarImage->setMaxRating('g');

// or the `maxRating()` helper method
$gravatarImage = gravatar($email);
$gravatarImage->maxRating('g');

// or its alias `r()` (as in the generated query string)
$gravatarImage = gravatar($email);
$gravatarImage->r('g');

// use the `setExtension()` method
$gravatarImage = gravatar($email);
$gravatarImage->setExtension('jpg');

// or the `extension()` helper method
$gravatarImage = gravatar($email);
$gravatarImage->extension('jpg');

// or its alias `e()` (as in the generated query string)
$gravatarImage = gravatar($email);
$gravatarImage->e('jpg');

// use the `setForceDefault()` method
$gravatarImage = gravatar($email);
$gravatarImage->setForceDefault(true);

// or the `forceDefault()` helper method
$gravatarImage = gravatar($email);
$gravatarImage->forceDefault(true);

// or its alias `f()` (as in the generated query string)
$gravatarImage = gravatar($email);
$gravatarImage->f(true);

// or use the `enableForceDefault()` method
$gravatarImage = gravatar($email);
$gravatarImage->setForceDefault(true);

$gravatarImage = gravatar();
$gravatarImage->enableForceDefault();
//...
$gravatarImage->forcingDefault(); // true
//...
$gravatarImage->disableForceDefault();
//...
$gravatarImage->forcingDefault(); // false

$avatar = gravatar('[email protected]')
    ->size(120)
    ->rating('pg')
    ->defaultImage('robohash')
    ->extension('jpg');

    'my_default' => [
        'size' => 80,
        'default_image' => 'mp',
        'max_rating' => 'g',
        'extension' => 'webp',
    ],
    'small' => [
        'size' => 40,
        'extension' => 'jpg',
     ],
    'medium' => [
        'size' => 120,
        'extension' => 'jpg',
     ],
    'large' => [
        'size' => 360,
        'default_image' => 'robohash',
        'max_rating' => 'pg',
     ],

    'default_preset' => 'my_default',

$gravatarImage = gravatar($email, 'small');

$gravatarImage = gravatar()->image($email, 'medium');

$gravatarImage = Gravatar::image($email, 'large');

// use the `setPreset()` method
$gravatarImage = gravatar($email);
$gravatarImage->setPreset('small');

// or the `preset()` helper method
$gravatarImage = gravatar($email);
$gravatarImage->preset('small');



namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use LaravelGravatar\Casts\GravatarImage;

class User extends Model
{
    protected $casts = [
        'gravatar' => GravatarImage::class,
    ];
}

use App\Models\User;

class UserController
{
    public function show(User $user)
    {
        $user->gravatar->preset('small');

        return view('users.show', [
            'user' => $user,
        ]);
    }
}

use LaravelGravatar\Casts\GravatarImage;

class Post extends Model
{
    protected $casts = [
        'gravatar' => GravatarImage::class.':small',
    ];
}

use LaravelGravatar\Casts\GravatarProfile;

class User extends Model
{
    protected $casts = [
        'gravatar' => GravatarProfile::class,
    ];
}
sh
php artisan vendor:publish --tag="gravatar-config"