Most applications now-a-days don’t even ask you to upload an image of yourself for use, unless of course it’s a dating website, or the DMV. Anyway, the majority of sites that will display your name and image such as forums, will use the e-mail address associated with your account and query Gravatar for your image.

Luckily there is a Laravel package that is really simple to use if you want this functionality for yourself.

Follow the installation instructions from the package, which are as easy as requiring it in composer and updating your app.php file with the service provider and alias, like you do for every package.

Once it is installed, hop over to your user model and add a new attribute:

Now in your views, you can do <img src="{!! auth()->user()->picture !!}" /> and it will output the image source of a 50×50 image of the user. If the e-mail is not found on Gravatar it will display the default Gravatar image.

If you don’t want the default Gravatar image, you can specify your own fallback like so:

I like this approach because you don’t have to create forms and scripts for your user to upload their image, as well as they can manage their avatar across a variety of sites all at the same time.