Explain Events and Listeners ?

Answers were Sorted based on User's Feedback



Explain Events and Listeners ?..

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

Explain Events and Listeners ?..

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

Post New Answer

More Laravel PHP Framework Interview Questions

What is a Views ?

1 Answers  


Please explain what is laravel?

1 Answers  


Explain bundles in laravel?

1 Answers  


Why are migrations important?

1 Answers  


What is a Middleware Parameters ?

1 Answers  


What is helpers in laravel?

1 Answers  


Explain the directory structure of laravel 5.6.

1 Answers  


What is gate in laravel?

1 Answers  


What are guards in laravel?

1 Answers  


What do you mean by laravel mix?

1 Answers  


How do I assign several roles to users and permit the users to perform some actions based on those roles?

1 Answers  


How to remove a complied class file?

1 Answers  


Categories