Laravel Events and Listeners: $dispatchesEvents in Models

Laravel Events and Listeners: $dispatchesEvents in Models

Laravel Daily

1 год назад

9,111 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@peepwebdev575
@peepwebdev575 - 17.04.2023 11:10

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

Ответить
@lahoucineoldakdim7778
@lahoucineoldakdim7778 - 15.12.2022 23:35

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

Ответить
@nemac23
@nemac23 - 11.11.2022 00:34

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

Ответить
@BelgranoK
@BelgranoK - 06.11.2022 03:58

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.

Ответить
@erwinyonathan6348
@erwinyonathan6348 - 02.11.2022 12:43

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

Ответить
@Jurigag
@Jurigag - 02.11.2022 01:15

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.

Ответить
@umarbabajidda9664
@umarbabajidda9664 - 02.11.2022 00:20

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

Ответить
@urosradovanovic8533
@urosradovanovic8533 - 01.11.2022 22:55

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.

Ответить
@shubhamsahuSD
@shubhamsahuSD - 01.11.2022 20:10

Talk about livewire features too...

Ответить
@psyick9543
@psyick9543 - 01.11.2022 15:26

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 OrderCreated)->created($order);
});

}

Ответить
@stojankukrika7242
@stojankukrika7242 - 01.11.2022 11:04

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?

Ответить
@___carl
@___carl - 01.11.2022 10:55

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

Ответить
@julienSibille
@julienSibille - 01.11.2022 09:52

Thanks !
What if you use verbs modifiers ?

Ответить
@learningtutorial3960
@learningtutorial3960 - 01.11.2022 09:03

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

Ответить
@abdirahmanburyar
@abdirahmanburyar - 01.11.2022 09:02

Am thee socond one who viewed and liked.

Ответить