29.07.2016 Views

laravel-5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Facades<br />

• Introduction<br />

• Using Facades<br />

• Facade Class Reference<br />

Introduction<br />

Facades provide a “static” interface to classes that are available in the application’s service container.<br />

Laravel ships with many facades, and you have probably been using them without even knowing it!<br />

Laravel “facades” serve as “static proxies” to underlying classes in the service container, providing<br />

the benefit of a terse, expressive syntax while maintaining more testability and flexibility than<br />

traditional static methods.<br />

Using Facades<br />

In the context of a Laravel application, a facade is a class that provides access to an object from the<br />

container. The machinery that makes this work is in the Facade class. Laravel’s facades, and any<br />

custom facades you create, will extend the base Illuminate\Support\Facades\Facade class.<br />

A facade class only needs to implement a single method: getFacadeAccessor. It’s the getFacadeAccessor<br />

method’s job to define what to resolve from the container. The Facade base class makes use<br />

of the __callStatic() magic-method to defer calls from your facade to the resolved object.<br />

In the example below, a call is made to the Laravel cache system. By glancing at this code, one might<br />

assume that the static method get is being called on the Cache class:<br />

.<br />

1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!