- Laravel 5.x Cookbook
- Alfred Nutile
- 194字
- 2021-07-14 09:56:50
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 them: https://laracasts.com/lessons/decoding-facades
推薦閱讀
- Spring 5企業(yè)級(jí)開發(fā)實(shí)戰(zhàn)
- Machine Learning with R Cookbook(Second Edition)
- BeagleBone Media Center
- CouchDB and PHP Web Development Beginner’s Guide
- Java程序設(shè)計(jì)
- 零基礎(chǔ)學(xué)Python網(wǎng)絡(luò)爬蟲案例實(shí)戰(zhàn)全流程詳解(入門與提高篇)
- Instant Ext.NET Application Development
- C/C++程序員面試指南
- PHP+MySQL+Dreamweaver動(dòng)態(tài)網(wǎng)站開發(fā)從入門到精通(第3版)
- C++反匯編與逆向分析技術(shù)揭秘(第2版)
- Learning AWS
- Couchbase Essentials
- Zabbix Performance Tuning
- Python Projects for Kids
- Learning Kotlin by building Android Applications