For example - this function uses a facade:
File::get('path/to/file.txt');
It turns out the underlying class that actually supplies File::get
is Illuminate\Filesystem\Filesystem
I looked at the Laravel 4.2 documentation - thats the version Im using - and also the api reference but I couldn't find anything that would explain how to someone who didn't know in advance how to find the "real" class to a facade.
this tutorial on Laravel facades gives a method of doing it which involves
File
classFacade
Facade#__callstatic()
method__callstatic()
, resolveFacadeInstance()
when getFacadeAccessor()
returns string files
This is a good demonstration of whats going on, but I wouldn't want to do this regularly.
My question is, knowing that the "facaded classes" you use in your app dont necessarily have a the same name or some convention to help you search the filesystem, how can someone - who doesn't know in advance what the underlying class is - find the underlying class for a laravel facade?
In a Laravel application, a facade is a class that provides access to an object from the container. The machinery that makes this work is in the Facade class. Laravel's facades, and any custom facades you create, will extend the base Illuminate\Support\Facades\Facade class.
A facade in Laravel is a wrapper around a non-static function that turns it into a static function. The word "wrapper" can also be used when describing design patterns. Wrapping an object to provide a simplified interface to it is often described as the "facade" pattern. So in short, the wrapper is the facade.
Since laravel largely uses facades rather every non static function has its equivalent facade available in service container, we must also follow the same way in our custom application. All of Laravel's facades are defined in the Illuminate\Support\Facades namespace.
Laravel includes the ability to seed your database with data using seed classes. All seed classes are stored in the database/seeders directory. By default, a DatabaseSeeder class is defined for you. From this class, you may use the call method to run other seed classes, allowing you to control the seeding order.
This is a nice resource: https://laravel.com/docs/facades#facade-class-reference other than that make sure to install some kind of intellisense plugin for whatever editor you happen to be using. Most of them allow you to Ctrl+Right-Click on a class/method and go to the definition.
It seems that you can use getFacadeRoot()
. For example, to find out what's behind the Mail
facade:
get_class(Mail::getFacadeRoot());
// in my case returns 'Illuminate\Mail\Mailer'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With