Laravel routes ARE A MESS!
Hello, I wanted to talk about a topic here that I also find interesting. I always talk a little about these topics because I see that no one mentions them and I notice them no matter how much, so I like to know the opinions of others, and they are always like that. A little bit of criticism. I believe that good things don't need much discussion, they're simply there. That's what I have my courses and books for.
Here we also have a route. This project, by the way, is the Laravel course. I'm updating to version 12, which is the latest. I'm always updating, and right now I don't have any more. But we also have a middleware function here that we can load in at least 3 ways:
Route***->middleware([])
Route::group(['middleware' => [])
Route::middleware([])
I like options, obviously the more things the better, but what I always want to get across, which I think is important, is that no matter what it is, the more options we will always have, I mean, it's neither black nor white, we have more options, but we do lose a little bit of what is sometimes readability or comprehension, or directly the piece we are working with becomes complicated, but we gain flexibility in that sense, so it's not a win-win, but there is always a term that is a little light gray, as I tell you, I prefer that they simply limit me to directly creating a grouped type route and the rest, that more than anything depends on the developer what they prefer, I am always a little bit like who says that, order the courses because I like to show variants and that you directly decide what you prefer.
Multiple types of routes
We have routes for drivers:
Route::get('user/{id}', 'UserController@show');
For components, Livewire components:
Route::get('/', App\Livewire\Dashboard\Category\Index::class)->name("d-category-index");
Volt:
Volt::route('volt/contact', 'volt.contact.general')->name('volt-d-category-index');
And of course views:
Route::get('/', function () {
return view('welcome');
})->name('home');
Let's remember that Laravel is not a pure MVC framework. We'll talk a little bit about that now, but that would be, as they say, from Laravel 5, when we have those functionalities, up to Laravel 6, because the components as such came out, I think it was version 7, so up to Laravel 5, what we had was in the routes, they were simply controllers.
I always work again when I want a project to use Livewire components, since I practically don't use the components based on Laravel because IAR gives me a lot of flexibility, as I've told you in other videos, Livewire is my scaffolding, I don't even know what name they give it, favorite for Laravel.
These route definitions for working with different components make the page difficult to read and maintain in general.
I agree to receive announcements of interest about this Blog.
We talked about why I think Laravel routes are becoming more complex and difficult to read, program, and use every day.
- Andrés Cruz