Automatic Facade’s coming to Laravel 5.4

Automatic Facade’s coming to Laravel 5.4

Coming in Laravel 5.4 is a new feature that will allow you to use any class as a Facade on the fly. If you are not familiar with Laravel Facades here is what they are:

Facades provide a “static” interface to classes that are available in the application’s service container. Laravel ships with many facades which provide access to almost all of Laravel’s features. Laravel facades serve as “static proxies” to underlying classes in the service container, providing the benefit of a terse, expressive syntax while maintaining more testability and flexibility than traditional static methods.

Automatic Facade Example

In Taylor’s example from the announcement here is how it works:

namespace App;

class Zonda 
{
    public function zurf()
    {
        return ‘Zurfing’;
    }
}

Then, in the routes or controller:

use Facades\ {
    App\Zonda
};

Route::get('/', function () {
    return Zonda::zurf();
});


Filed in: Laravel 5.4 / Facade


Newsletter

Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Full Stack or Back-End Developer
Alexandria, VA; Tallahassee, FL; Orlando, FL
Marketing for Change
Full Stack Software Engineer
Atlanta, GA or Remote
Voxie
Laravel/PHP Developer
Chicago, IL
Neon One
Software Engineer, Web Applications
Vaughan, ON, Canada
Blast Motion
Contract Services Software Engineer (Laravel | Vue | Tailwind)
Remote
Riverbed Technology
Senior Laravel Developer
Wilmington, NC
GE Software Inc.
Senior Full Stack Developer (PHP | Vue | DDD)
Charleston, SC
MassageBook