Automatic Event / Listener Discovery

Taylor Otwell
Taylor Otwell

Yesterday we shipped Laravel 5.8.9. Included in this release is the ability to have the framework automatically register your events and listeners. However, since this is a patch release, you must opt-in to this behavior. To do so, define the shouldDiscoverEvents method on your application's EventServiceProvider. To enable event discovery, this method should return true:

/** * Determine if events and listeners should be automatically discovered. * * @return bool */publicfunctionshouldDiscoverEvents(){  returntrue;}

By default, all listeners within your application's Listeners directory will be scanned. If you would like to define additional directories to scan, you may override the discover events within the method in your EventServiceProvider.

In production, you likely do not want the framework to scan all of your listeners on every request. Therefore, during your deployment process, you should run the event: cache Artisan command to cache a manifest of all of your application's events and listeners. This manifest will be used by the framework to speed up the event registration process.

We hope you enjoy this new feature!

At Ltd, We offer web design company London at an unbeatable cost. Our main motive only is customer satisfaction.

Taylor Otwell
Taylor Otwell

Latest Stories

Here’s what we've been up to recently.

Request a code sample

Certified Quality. Great Prices

We use cookies to improve your experience and to help us understand how you use our site. By using this site, you accept our use of cookies. Cookie Infox