Laravel without Facades Part 1: Routing

Frano Šašvari
1 min readApr 11, 2019

--

This is my second blog post about using Laravel framework without Facades. First post was about explaining why not to use Facades, static classes, and helper functions. The second post is accompanied by concrete examples.

So today, I’ll show you how to use Router class and set up routes for your Laravel project.

First, we need to refactor our Route service provider:

app/Providers/RouteServiceProvider.php

In RouteServiceProvider we injected Router class via dependency injection to base map() method. Later on, we can use it in mapWebRoutes() and other map() methods like mapApiRoutes(), etc.

And then we can normally define our routes in routes/web.php:

routes/web.php

Basically, that’s it, we refactored RouteServiceProvider and defined all of our application routes in “routes” folder.

Thanks everyone for reading this series showing you how to use Laravel without Facades. In next post, I’ll refactor some of the built-in Middlewares in Dependency Injection way, instead of Facade usage. Stay tuned!

Previous article: Part 0: Intro

--

--

Frano Šašvari

Web developer from Croatia, currently working for Typeqast