Example of Laravel Observers and Events Listeners Used TOGETHER

preview_player
Показать описание
Interesting short example of how Eloquent Model Observers and Events/Listeners can be used together, they are not mutually exclusive.

Related video:

- - - - -
Support the channel by checking out our products:
Рекомендации по теме
Комментарии
Автор

It all makes sense. Not only do you separate the event logic from the observer (which helps reuse it somewhere else) but you also get easier refactoring

Voltra_
Автор

Just done that few weeks ago. It makes the controller clean enough. 👌

NepalByteCode
Автор

I have done the exact same thing. Firing an event in a model-observer. In my case I wanted to send an email only if my cronjob updates the model. If one of the users makes an update nothing else should happen. Additionally I think emails should not be send within any model event

Tikey
Автор

I think depends on usecase. Sometimes we have to use both and sometimes one of them.

NotBeHaris
Автор

Interesting and useful approach. Tnx for sharing idea :)

stojankukrika
Автор

In Observer, sometimes not work especially the logic in updated method e.x. clear the cache… why?

alila
Автор

I use this pattern, when im sending email when transaction is done.

johnmarkvictorino
Автор

I considered doing this as well to avoid duplicate logic when checking my event listeners. (i.e. checking what value is dirty etc)
But quickly came to the conclusion that having a few extra if statements that get duplicated is worth the price compared to further abstracting the event system.

Abstracting events even more makes debugging faulty event chains harder and harder.
As a result Unless you have the same logic check 50x times in different event handlers I would not consider doing this.

petermancloud
Автор

When I saw this earlier I thought the concept is great but observers of course (as pointed out in another of your videos) kind of hides what's happening from a new dev checking out the controller for the first time, with that said - if design requires this type of thing then it's worth the trade off, of course this is why we have code comments after all..

dcxwms
Автор

Nice concept. Nice PHPStorm layout, How you did that?

saydfuad
Автор

Can You Suggest me best packages to generate barcode & QR Code in Laravel

Jayaram-nmlq
Автор

Possible you forgot the link to the other video you mention at 2:30? Thank you

beatnu
Автор

I recently started working with concept of Hexagonal Architecture and since then started to treat all these as controllers which basically don't have much code inside, instead they are calling other services.

I came up to this idea when I realized that I want execute same actions from different parts of my application.
I think a video of Hexagonal Architecture with pros/cons could be interesting for your audience.
Of course it is based on SOLID principles, but the way of thinking is completely different comparing to classic Laravel MVP patterns.

alexaverkiyev
Автор

Sir according to me when we doing bulk data opration then we need to go with event else we can use observe. Is this a right way to select when we use observe or event?

rraghav
Автор

Where's the Mortal Kombat thumbnail? 🔥😆

ricko