Google Fonts Loader Laravel Package

Posted 27th May 2019

The majority of websites I build utilise custom web fonts, and more often than not these will be Google hosted web fonts. I wanted a way that would make adding these fonts to my Laravel projects quick, easy and manageable.

Before

Previously, I would add Google fonts to my Laravel project in one of 2 ways. Either by importing the required font(s) directly into my css/sass file.

@import url('https://fonts.googleapis.com/css?family=Open+Sans');

Or by simply linking to the stylesheet using the embed code Google fonts gives you.

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans" />

There are a few reports on which option to choose out of the above, and the most often consensus is to not use the @import method.

After

The package is simple, it includes the fonts using the second method above, but gives you a tidy and more readable class in which to do it. Here's an example.

{!! GoogleFontsLoader::load([
     'Open Sans:400,700'
]) !!}

That's all there is to it. Head on over to the github repo to read more about the installation of the package and give it a try.