Explain Events and Listeners ?
Answers were Sorted based on User's Feedback
Answer / surbhi
Events and Listeners serve a great way to decouple a web application, since one event can have multiple listeners which are independent of each other.
The events folder created by the artisan command includes the following two files
1. : event.php
2. :SomeEvent.php.
Event.php
<?php
namespace AppEvents;
abstract class Event{
//
}
As mentioned above, event.php includes the basic definition of class Event and calls for namespace AppEvents. Please note that the user defined or custom events are created in this file.
SomeEvent.php
For example, if we need to initialize order variable in the constructor for registering an event, we can do it in the following way -
public function __construct(Order $order)
{
$this->order = $order;
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / Rajendra Kumar Nepane
Events are instances of the PHP Event Sourcing principle, where an object is created when something significant happens. Listeners are functions that get called when a specific event occurs. In Laravel, events are dispatched using the event facade, and listeners are registered with event service provider. This allows for decoupling components within the application.
| Is This Answer Correct ? | 0 Yes | 0 No |
What is a Views ?
Please explain what is laravel?
Explain bundles in laravel?
Why are migrations important?
What is a Middleware Parameters ?
What is helpers in laravel?
Explain the directory structure of laravel 5.6.
What is gate in laravel?
What are guards in laravel?
What do you mean by laravel mix?
How do I assign several roles to users and permit the users to perform some actions based on those roles?
How to remove a complied class file?