Part 9: Eloquent Events - Laravel 5.4 New Features
Автор: DevMarketer
Загружено: 2017-02-20
Просмотров: 19139
Описание:
In Laravel 5.4 we can now tie eloquent events to our normal event classes. This allows us to tuck custom functionality to when new models and items are added to our database with very little effort.
While it might seem confusing at first for a newcomer, the events system requires several files but it makes sense once you wrap your head around it.
The file that controls all events is the EventServiceProvider. This is the file that displays all the events to listen for and the listeners to fire when the event is triggered. You can set up these relationships in a basic associated array format, with as many listeners as you want tied to a specific event.
Once you set up the relationship you can generate the files needed, by using the artisan console command:
php artisan event:generate
This will create an Events and a Listeners folder with the new events and listeners files inside them.
We will customize the event file only because we want to tell the event to pass a user eloquent object along to the listener, otherwise there would be no other need to customize this file. By customizing this file, we tell it to pass the user object to the listener.
In the listener, we can tell the listener which code to execute by putting the code in the Handler() function. For this tutorial, this is where we add the Mail command.
This is the basic event/listener relationship, but when we want to tie it to your Eloquent events, then we establish the connection in our model. In our case, it is the User model. In the user model, we will create a new protected attribute called $events and then set up the eloquent event to our custom Event Classes as shown in the video.
Now when the eloquent event fires, it triggers our custom Event class and then fires the listener.
For more information about Events/Listeners in general:
https://laravel.com/docs/5.4/events
For more information about Eloquent Events:
https://laravel.com/docs/5.4/eloquent...
Повторяем попытку...

Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: