New in Laravel 10.9: Middleware Classes with Static using() Methods

preview_player
Показать описание
Another new feature in Laravel - you can call the Middlewares by classes with new static methods.

- - - - -
Support the channel by checking out my products:

- - - - -
Other places to follow:
Рекомендации по теме
Комментарии
Автор

I'm always down to using more progrmatic approach to everything, instead writing in strings and arrays.

rizwannasir
Автор

I like the old way, having longer names in route files complicates everything. That's the purpose of having aliases. To make code short and simple.

smith
Автор

At the beginning of learning laravel i was so confused how this auth works and what is the logic. Somebody said it's a laravel magic function. In programming there is no magic in my opinion(even though lot of laravel developer's use this magic word😅). But this approach, i would like to appreciate. I would like to choose this way. It will be very helpful for new learners. Thanks for sharing. Keep it up.

alhira
Автор

That's great, but aliases make it easier to remember, and they make purpose of the middleware class clear. But new syntax has better ide support

LeadDev-ic
Автор

The strings are better in this case since some of the middleware class names aren't descriptive compared their associated alias. And even the argument that classes would make navigating to them easier is a moot point since the Laravel Idea plugin can point me to the middleware directly from the alias.

KastsEcho
Автор

String aliases are inferior to more explicit expressions. Looking at them doesn't show what is aliased at all (a class? a method?...). It requires a lot of framework knowledge to understand what is going on with all the strings that hide the codeflow for breviety. For me as a supervisor it's hard to know every detail of all the framworks. Requiring unnecessary strings are an argument against a framework. Therefore it's good to have the option to use the classes itself!

fordprefect
Автор

I use ::class constants all the time, because times when you have to pass class as a string are already far behind

cardboarddignity
Автор

What about passing param to middleware class such auth:admin in this new feature should i use new SomeMiddleware(param) instead of SomeMiddleware:class?

mohamadcheaib
Автор

better approach so far!
btw Povilas why you using github in light mode? 😅

ricko
Автор

Something I didn't get clearly is custom middleware with arguments

Will the using static method be available in all middlewares to pass arguments?

chibuikeumezinwa
Автор

It looks much more verbose, which is why the very concept of aliases had been introduced to begin with.

Sahrokh
Автор

I think that using directly the class is better. I always avoid using configuration by string because they hide the logic behind them.

BelgranoK
Автор

ı don’t like it because it's just makeup.

They love to put on makeup when they can't find anything to do.

assoftTR