Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Facade: in Route, DB, Gate

Premium
4 min read

Diving deep into Laravel source code reveals more patterns. In this case, we can spot a heavy usage of the Facade pattern.


Route Facade

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...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.