Git Product home page Git Product logo

gravatar's Introduction

Gravatar for Laravel 5.x and 6.0

Total Downloads Latest Stable Version License

Installation

First, pull in the package through Composer via the command line:

composer require creativeorange/gravatar ~1.0

or add the following to your composer.json file and run composer update.

"require": {
    "creativeorange/gravatar": "~1.0"
}

Then include the service provider within (Laravel 5.3 or below) app/config/app.php.

'providers' => [
    'Creativeorange\Gravatar\GravatarServiceProvider'
];

If using Laravel 5.4, include service provider withing config/app.php

'providers' => [
    Creativeorange\Gravatar\GravatarServiceProvider::class
];

If you want to use the facade, add this to de bottom of app/config/app.php And, for convenience, add a facade alias to this same file at the bottom:

'aliases' => [
    'Gravatar' => 'Creativeorange\Gravatar\Facades\Gravatar',
];

If you are using Laravel 5.4 or greater, add as follows, add to config/app.php

'aliases' => [
    'Gravatar' => Creativeorange\Gravatar\Facades\Gravatar::class,
];

Finally, publish the config by running the php artisan vendor:publish command

Usage

Within your controllers or views, you can use

    Gravatar::get('[email protected]');

this will return the URL to the gravatar image of the specified email address. In case of a non-existing gravatar, it will return return a URL to a placeholder image. You can set the type of the placeholder in the configuration option fallback. For more information, visit gravatar.com

Alternatively, you can check for the existence of a gravatar image by using

    Gravatar::exists('[email protected]');

This will return a boolean (true or false).

Or you can pass a url to a custom image using the fallback method:

    Gravatar::fallback('http://urlto.example.com/avatar.jpg')->get('[email protected]');

Configuration

You can create different configuration groups to use within your application and pass the group name as a second parameter to the get-method:

There is a default group in config/gravatar.php which will be used when you do not specify a second parameter.

If you would like to add more groups, feel free to edit the config/gravatar.php file. For example:

return array(
	'default' => array(
		'size'   => 80,
		'fallback' => 'mm',
		'secure' => false,
		'maximumRating' => 'g',
		'forceDefault' => false,
		'forceExtension' => 'jpg',
	),
	'small-secure' => array (
	    'size'   => 30,
	    'secure' => true,
	),
	'medium' => array (
	    'size'   => 150,
	)
);

then you can use the following syntax:

Gravatar::get('[email protected]', 'small-secure'); // will use the small-secure group
Gravatar::get('[email protected]', 'medium'); // will use the medium group
Gravatar::get('[email protected]', 'default'); // will use the default group
Gravatar::get('[email protected]'); // will use the default group

Alternatively, you could also pass an array directly as the second parameter as inline options. So, instead of passing a configuration key, you pass an array, which will be merged with the default group:

Gravatar::get('[email protected]', ['size'=>200]); 

gravatar's People

Contributors

jacotijssen avatar rebelinblue avatar osaigbovoemmanuel1 avatar joshlewis avatar mikeerickson avatar carlos3duardo avatar sburina avatar tobias-nitsche avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.