官术网_书友最值得收藏!

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...

  1. Make a folder called Facades in your app folder.
  2. Then add a file called APIClient.php and make it look like this:
  3. Then scroll way down to the Fa?ade section of this file, where we can register the Facade in our config/app.php file like this:
  4. Now, let's see it working in a test by adding the method called seeing_our_facade_work to our test:
  5. 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

主站蜘蛛池模板: 岫岩| 乐都县| 武川县| 钟祥市| 黄石市| 拉孜县| 鹿泉市| 错那县| 年辖:市辖区| 克什克腾旗| 息烽县| 焦作市| 平遥县| 仪陇县| 罗田县| 五莲县| 方城县| 连山| 莱阳市| 元江| 泰安市| 宝应县| 临西县| 苍梧县| 万全县| 尖扎县| 盘锦市| 潮州市| 晋宁县| 民和| 沛县| 涪陵区| 弥勒县| 富宁县| 尖扎县| 乐都县| 武定县| 尼木县| 孟村| 平泉县| 罗田县|