Diving deep into Laravel source code reveals more patterns. In this case, we can spot a heavy usage of the Facade pattern.
One of the most interacted Facades - Route. We use it every day to define routes in our application:
Route::resource(...);Route::get(...);Route::post(...);Route::group(...);
And we don't even think about the fact that it is a Facade! Even if the use
statement at the top tells us that:
use Illuminate\Support\Facades\Route;
This was made into a Facade to allow us to use the Route
class without creating a new instance of it:
(new Route)->get(...);
Just imagine how much more code we would have to write if we had to create a new instance of the Route
class every time we wanted to define a new route.
So this is where Facades come in handy. They allow us to use the classes without creating new instances of them:
Illuminate/Support/Facades/Route.php
class Route extends Facade{ /** * Get the registered name of the component. * * @return string */ protected static function getFacadeAccessor() { return 'router'; }}
And of course, in order to use the Route
Facade - there is some...