How to Load Gravatar Image in Laravel
Today, I’m going to let you know how to load the gravatar image in Laravel. We’re going to use creativeorange/gravatar
package.
Table of Contents
Install Package
Run this artisan command to install the package:
composer require creativeorange/gravatar
For Laravel 5.3 or below, we need to add this service provider and aliase in config/app.php
file:
'providers' => [
//....
'Creativeorange\Gravatar\GravatarServiceProvider::class',
],
'aliases' => [
//....
'Gravatar' => 'Creativeorange\Gravatar\Facades\Gravatar::class',
],
Finally, publish the config by running the php artisan vendor:publish
command.
Use in Controller
We can easily get gravatar image using this package. Here’re some examples:
// import
use Creativeorange\Gravatar\Facades\Gravatar;
// get image
Gravatar::get('[email protected]');
// set fallback image
Gravatar::fallback('http://example.com/avatar.jpg')->get('[email protected]');
Use in Blade File
Here’s the example to use in blade (view) file:
<img src="{{ Gravatar::get('[email protected]') }}">
Configuration
We’re able to define some sizes & options in the package’s config file. The config file is located at config/gravatar.php
. Here’s an example of config:
return [
'default' => [
'size' => 80,
'fallback' => 'mm',
'secure' => false,
'maximumRating' => 'g',
'forceDefault' => false,
'forceExtension' => 'jpg',
],
'small-secure' => [
'size' => 30,
'secure' => true,
],
'medium' => [
'size' => 150,
]
];
Then we use the following syntax:
Gravatar::get('[email protected]', 'small-secure');
Gravatar::get('[email protected]', 'medium');
Gravatar::get('[email protected]', 'default');
Gravatar::get('[email protected]'); // will use the default group
We can also pass config like:
Gravatar::get('[email protected]', ['size'=>200]);
That’s all. Thank you. ?
Comment
Preview may take a few seconds to load.
Markdown Basics
Below you will find some common used markdown syntax. For a deeper dive in Markdown check out this Cheat Sheet
Bold & Italic
Italics *asterisks*
Bold **double asterisks**
Code
Inline Code
`backtick`Code Block```
Three back ticks and then enter your code blocks here.
```
Headers
# This is a Heading 1
## This is a Heading 2
### This is a Heading 3
Quotes
> type a greater than sign and start typing your quote.
Links
You can add links by adding text inside of [] and the link inside of (), like so:
Lists
To add a numbered list you can simply start with a number and a ., like so:
1. The first item in my list
For an unordered list, you can add a dash -, like so:
- The start of my list
Images
You can add images by selecting the image icon, which will upload and add an image to the editor, or you can manually add the image by adding an exclamation !, followed by the alt text inside of [], and the image URL inside of (), like so:
Dividers
To add a divider you can add three dashes or three asterisks:
--- or ***

Comments (0)