Laravel Middleware is NOT Only for Restrictions

preview_player
Показать описание
Let me show you a few examples where the Middleware class is not restricting anything but actually setting some variables and just moving on.

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

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

I use Middleware like this for set user online status, when user use application Middleware set his last visit date, then we can use this information for display 'USERNAME was online 5 minutes ago' etc

PsyHooZ
Автор

This is a very dangerous thing to do.... it should be used as a temporary fix and later do it "the right way"
There is some good magic stuff in Laravel and this is one which has a big potential to be bad.
Stuff like this you can do on some smaller|personal projects (changing something what is sent in the middle of the way),
but in bigger teams (15+ developers ) from my experience, stuff like this introduces big confusion, especially by more junior developers.

easyvideott
Автор

The most valuable YouTube channel for me. Thank you for your awesome work.

ellmatic
Автор

Don't forget the AfterMiddleware class to transform responses on a global level. Useful for large apps where a refactor isn't possible.

mikescola
Автор

Great course content, as your student on Laravel Daily and based on what I have learnt from you, I suggest you improve the language locale code syntax by using the recent Match Operator. Thanks

Bbtechjourney
Автор

Don't like first example anyway, request should be immutable anyway. You want to do some mappings? Do it properly in controller so it's actually known, like create data array which comes from request and add it there.

Jurigag
Автор

Middlewares are very useful, even can be used to log requests in the terminate method.

mehdidaalvand
Автор

Some time ago I wrote a middleware to cast integer values in GET-request to real integers. Same with float. As they always came as strings to the controller.

Tikey
Автор

Sir how to combine multiple collection and return in view as a single one for iteration?

pratikdesai
Автор

Off topic: What about setting the language from the browser http header as long as there is no other value?

paulfontaine
Автор

in my laravel 11 project middleware is not working. i don't know why. i see no kernel so how do i fix it? cause now sensitive pages are also accessible to normal users.😢

ArshAudioBooks
Автор

For an API we logged every request to better debug requests made by our partner whos building the frontend.

Tikey