Automatic facades in Laravel 5.4

Snippet published on February 19, 2017 by @markvaneijk in Laravel

It's awesome. The automatic facades feature in the new Laravel, by calling your class using it's own namespace within the Facades namespace.

For example you have a Form-class. You can automatically turn it into a class that uses facades by calling it into the Facades namespace, to use it directly into your controller or routes.

It that simple!


<?php

// app/Form.php

namespace App;

class Form {

    public function field()
    {
        return '<input type="text">';
    }
}

// routes/web.php

use Facades\App\Form;

Route::get('facades', function() {
    return Form::field();
});