Laravel ships with so many facades which provide access to almost all of the Laravel’s features. Laravel facade serves as “static proxies” to underlying classes in the service container. All of Laravel’s facades are defined in the Illuminate\Support\Facades namespace.

use Illuminate\Support\Facades\Cache;

Route::get('/cache', function () {
    return Cache::get('key');
});

Laravel Facades

Laravel Facades provide a “static” interface to classes that are available in the application’s  service container. Now, we will take one example to illustrate the Laravel Facade.

First, download the Fresh Laravel. In the app directory, make one folder called **Person. **

In that folder, create one file called Person.php.

<?php

// Person.php

namespace App\Person;

class Person
{
    public function getName()
    {
        return 'AppDividend';
    }
}

To call this method, we just need to include this file in the routes >> web.php file.

<?php

// web.php

use App\Person\Person;

Route::get('/', function () {
    $person = new Person();
    echo $person->getName();
});

So, here in this example, the Person.php file has one non-static method. So, we have made one object of it and then call the method, and we can see the output in the browser.

#laravel #laravel facades #person.php

Laravel Facades: The Complete Guide
1.65 GEEK