PHP code example of tomshaw / laravel-gravatar

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

    

tomshaw / laravel-gravatar example snippets


use TomShaw\Gravatar\Facades\Gravatar;

Gravatar::src('[email protected]', size: 200, default: 'retro');
Gravatar::hash('[email protected]');
Gravatar::profileUrl('[email protected]');
Gravatar::qrCode('[email protected]', size: 350);

Gravatar::has('[email protected]');       // bool     — HTTP
Gravatar::profile('[email protected]');   // ?Profile — HTTP

Gravatar::for($user->email)->size(200)->retro()->url();
Gravatar::for($user->email)->size(200)->rating('pg')->exists();

use TomShaw\Gravatar\Concerns\HasGravatar;

class User extends Authenticatable
{
    use HasGravatar;
}

$user->gravatarUrl(size: 200, default: 'retro');
$user->gravatarProfileUrl();
$user->gravatarQrCode(size: 350);

$user->hasGravatar();      // HTTP
$user->gravatarProfile();  // HTTP

protected function gravatarEmailColumn(): string
{
    return 'contact_email';
}

$profile = Gravatar::profile('[email protected]');

$profile->displayName;
$profile->location;
$profile->jobTitle;
$profile->company;
$profile->pronouns;
$profile->verifiedAccounts;

$profile->get('timezone');  // any field, straight from the raw payload
$profile->toArray();        // the whole payload

Gravatar::qrCode($user->email, size: 350, version: 3, type: 'gravatar');

Gravatar::src($email, hash: 'md5');
Gravatar::for($email)->md5()->url();

use TomShaw\Gravatar\Facades\Gravatar;

$fake = Gravatar::fake(
    profiles: ['[email protected]' => ['display_name' => 'Ada Lovelace']],
    existing: ['[email protected]'],
);

expect($user->gravatarProfile()->displayName)->toBe('Ada Lovelace');
expect(Gravatar::has('[email protected]'))->toBeTrue();
expect(Gravatar::has('[email protected]'))->toBeFalse();

$fake->assertLookedUp('[email protected]');
$fake->assertNotLookedUp('[email protected]');
$fake->assertNothingLookedUp();

return [
    'hash' => 'sha256',            // or 'md5'
    'size' => 80,
    'default' => 'mp',
    'rating' => 'g',
    'secure' => true,
    'extension' => 'jpg',
    'fallback' => null,            // local image for <x-gravatar />
    'api_key' => env('GRAVATAR_API_KEY'),
    'cache' => [
        'store' => null,           // null uses the app default
        'ttl' => 3600,             // 0 disables
        'prefix' => 'gravatar',
    ],
    'email_column' => 'email',     // read by HasGravatar
];
bash
php artisan vendor:publish --tag=gravatar-config
bash
php artisan vendor:publish --tag=gravatar-views