PHPackages                             tournasdim/laravel4-getgravatar - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tournasdim/laravel4-getgravatar

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tournasdim/laravel4-getgravatar
===============================

A Laravel 4 package . Given an email address it automatically retrieves an Avatar from Gravatar's website . For logged-in users , their email address is automatically generated , through the Auth adapter Interface . Three Adapters are supported : Auth , Sentry and Confide .

V1.0.0(12y ago)102722[1 issues](https://github.com/tournasdim/Laravel4-getgravatar/issues)MITPHPPHP &gt;=5.3.0

Since Jul 3Pushed 12y ago2 watchersCompare

[ Source](https://github.com/tournasdim/Laravel4-getgravatar)[ Packagist](https://packagist.org/packages/tournasdim/laravel4-getgravatar)[ Docs](https://github.com/tournasdim/getgravatar)[ RSS](/packages/tournasdim-laravel4-getgravatar/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (1)Used By (0)

Laravel4-Getgravatar
====================

[](#laravel4-getgravatar)

An avatar is a graphical representation of a user . It could be the person’s picture , or a random icon they want to be associated with . All a user has to do is to register an account based on their email address and upload an avatar to associate with that account . On the other side of the coin , webmasters that want to let their visitors graphically identify themselves have to implement a REST request to Gravatar's API . The request is just an URL encoded string with the email address of the user . If Gravatar's servers recognize this email address as a registered user , the user's associated Avatar is send back . Webmasters can also configure their system to automatically display an Identicon when a user has no registered Gravatar . This library is meant to be used as a Laravel 4.0 / 4.1 package and help PHP developers be concentrated on more important parts of their Laravel project .

### Prerequisites :

[](#prerequisites-)

It is assumed that you already have a working Laravel 4 project . Basic knowledge with Laravel's concepts are also required . For instance : Route , Controller , Blade or Authentication-adapter shouldn't be "strange" words to you .

\##Installation :

- 1. Update your Laravel's `composer.json` file

```
{
		"require": {
		"laravel/framework": "4.0.*" ,
		"tournasdim/laravel4-getgravatar": "dev-master"
		}
	}
```

- 2. Run a `composer update` command from your project's root
- 3. Add the Gravatar Service Provider ***and an alias*** to your configuration file `app/config/app.php`:

```
'providers' => array(
		'Illuminate\Foundation\Providers\ArtisanServiceProvider',
		'Illuminate\Auth\AuthServiceProvider',
		'Illuminate\Cache\CacheServiceProvider',
		'Illuminate\View\ViewServiceProvider',
		'Illuminate\Workbench\WorkbenchServiceProvider',
		` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `
		'Tournasdim\Getgravatar\GetgravatarServiceProvider'	),
```

```
'aliases' => array(
		'App'             => 'Illuminate\Support\Facades\App',
		'Artisan'         => 'Illuminate\Support\Facades\Artisan',
		'Auth'            => 'Illuminate\Support\Facades\Auth',
		'Blade'           => 'Illuminate\Support\Facades\Blade',
		'View'            => 'Illuminate\Support\Facades\View',
		````		````		````		````			````		````
		'Gravatar' => 'Tournasdim\Getgravatar\Facades\Getgravatar' ,
```

- 4. Optionally "transfer" the configuration file of this package into ***"app/config/packages"*** directory . This will give you the option to customize basic features of this package . Run `php artisan config:publish "tournasdim/laravel4-getgravatar"` and open the file ***"app/config/packages/tournasdim/getgravatar/config.php"*** to customize basic functionality (size , customGravUrl , defGrav , authAdapter , maxRating) . Every option is explained in the configuration file , drop me an issue if you need specific help though .

\##Un-Installing the package :

1. Remove this package's registration from Laravel's `composer.json` file
2. Remove Gravatar Service Provider from config file `app/config/app.php`
3. Remove the alias from the config file `app/config/app.php`
4. If step 4 of the installation process was implemented , manually remove the "tournasdim" directory from `app/config/packages` directory . Instead of manually removing this directory , alternatively use the CLI : `php artisan gravatar:uninstall `
5. Run a `composer update` command .

### Basic usage :

[](#basic-usage-)

#### The "Gravar" Class accepts three optional parameters .

[](#the-gravar-class-accepts-three-optional-parameters-)

- ***$size :*** Expresed in pixels , if defined then it will overwrite the value defined into the configuration file .
- ***$randomize :*** This feature is enabled by default ,the Class will randomly select a name from a Pool of accepted names ('mm' , 'identicon' , 'monsterid' , 'wavatar' , 'retro') . If the email send to Gravatar's server is not recognized then this specified Avatar will be returned instead . By setting the value of this option to ***"false"*** , random is turned off , and the value of `defGrav` will be used as parameter (a predefined fallback avatar) .
- ***$email :*** Default is set to null . Logged-in user's email is resolved by using the current Auth's adaptor Interface . Which adapter is currently used by the application is defined into a key ("authAdapter") of the configuration file . By specifying an email , we actualy force the Class to use this as value into the query string . This feature is handy for non registered users , we will use their specified email (on comment sections) to build our query string .
- Another important configuration option is made directly into the configuration file ***"app/config/packages/tournasdim/getgravatar/config.php"*** (supposed that step 4 of the installation process was applied ) . If you'd prefer to use your own default fallback-image (perhaps your logo , a funny face , whatever), then you can easily do so by supplying a custom URL to an image . Just set your prefered Url into the ***"customGravUrl"*** variable of this package's configuration file . If the email send to Gravatar's server is not recognized , an image from the custom Url will be returned instead . Keep in mind though that the ***"size"*** attribute isn't active anymore because Gravatar's server won't crop our custom image (make sure you have uploaded the right size for the custom fallback image) .

### Practical examples :

[](#practical-examples-)

#### Calling an Avatar from a Route

[](#calling-an-avatar-from-a-route)

- ***Example 1 :***

```
/*
Defining an Email address  :
1) If recognized by Gravatar's server , its accompanied image is returned , else
2) An alternative Avatar is returned (randomly chosen from a "pool" )
 */
Route::get('/' , function()
	{

	return Gravatar::get( null , false , 'johndoe@gmail.com' ) ;

	});
```

- ***Example 2 :***

```
/*
* No Email address defined : For logged-in users , their email address will be send to  Gravatar's API .
*/
Route::get('/' , function()
	{

	return Gravatar::get() ;

	});
```

- ***Example 3 :***

```
/*
Disable "random image" , which Avatar is returned depends on :
1) if "customGravUrl" is defined , then return the image from that Url
2) if "customGravUrl" was not defined then use the image specified in "defGrav".
 */
Route::get('/' , function()
	{

	return Gravatar::get(null , false) ;

	});
```

- ***Example 4 :***

```
// Defining an Avatar from a Route and passing it to the View
Route::get('/' , function()
	{

	$gravatar = \Gravatar::get() ;
	return  View::make('welcome')->with('gravatar' , $gravatar) ;

	});
```

#### Calling an Avatar from a Controller

[](#calling-an-avatar-from-a-controller)

- ***Example 1 :***

```
