Using the Facade pattern
Using the preceding work, let's take it one step further in how easy it is to use this Client in our code.
Getting ready
Install Guzzle and set up the provider just as we did previously, and you are ready for this next recipe.
How to do it...
- Make a folder called
Facades
in yourapp
folder. - Then add a file called
APIClient.php
and make it look like this: - Then scroll way down to the
Façade
section of this file, where we can register theFacade
in ourconfig/app.php
file like this: - Now, let's see it working in a test by adding the method called
seeing_our_facade_work
to our test: - Now run the test:
How it works...
So, the amount of work is all it takes to make your Provider just as easy to use as View, File, Storage, and all the other Facades that come from Laravel that make it easy and enjoyable to use.
Also, we can change the test to show it being just as easily swapped out. We will cover this in the testing chapter.
See also
- Laracasts and another great video from...