Laravel Events and Listeners: $dispatchesEvents in Models

preview_player
Показать описание
There's one less-known way to define the events and listeners if they are related to a specific Model. Also, let's discuss the philosophical "hidden magic" in Laravel.

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

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

The value of the $dispatchesEvents should be the Event that is fired rather than the Listener that should be invoked.
In this case we would use Registered::class and still require the configuration of the listener in the EventServiceProvider

___carl
Автор

I was literally asking myself, when should i user observers vs Model Events! Thank you

peepwebdev
Автор

Just as I was thinking about the documentation issue - he mentioned it in the video. I think I would do my future self and other developers a favor by adding a comment right before or after the method that is being listened to or has an event firing somewhere. I think that would make it easier for another developer down the line

umarbabajidda
Автор

Most frameworks have some hidden magic but none of them like Laravel. I can deal with it but some collegues have a hard time when they have to code with that in mind.

BelgranoK
Автор

I add second guard admin with prefix admin everything work but events like Login and Register execute to all guards
how to skip it in admin guard

lahoucineoldakdim
Автор

Sir, can I only use events with $dispatchEvents or can we use actions as well? why action class ? so that I do not need to setup extra listener, thus less code

erwinyonathan
Автор

Thanks !
What if you use verbs modifiers ?

julienSibille
Автор

Beginner question but what would be the advantage of having an event over just chaining a job in the queue?

nemac
Автор

Hi Pavilas. Did you or some other dev have this issue? In some cases, if the user selects a date range for a large amount of data(we can't predict it because it depends on the specific organization) I like to show data in a table but in some other cases - if a number of records over some execution time or a number of records to send them to email CSV export data and put it on queue to make that export, to not stop all system to other users. is that possible to make somehow?

stojankukrika
Автор

I always wondered why to bother with listeners etc. What do you think of using the boot() function on the Model? e.g.

public static function boot()
{
parent::boot();

self::created(function ($order) {
(new
});

}

psyick
Автор

One suggestion: Make laravel paypal server side integration video/course if you can.(can't find good detailed one)
Used for paypal and credit card processor over paypal.
Would like to use stripe but not possible in my Country.
Thank you for all your work.

urosradovanovic
Автор

hello brohter, can you help make video tutorial, how to add export buttons to yajra datatable in laravel without your use your QuickAdminPanel?

learningtutorial
Автор

Personally I feel this is really bad idea. You don't know that there is any event dispatched, how you even test if let's say there will be multiple things to do on created event? Normally you just check if event was dispatched, this way you pretty much need to test and mock everything in those listeners.

Also events in application should stay separated from your models, for example you might to want to dispatch those events to some other stuff, lets says sqs, sns etc. This way there is no such option.

Jurigag
Автор

Am thee socond one who viewed and liked.

abdirahmanburyar