Here are some of the records I used for the event
Create Event
Executes the following command, after execution completes, a deleteevent.php file appears under App\events, and the event is defined in the secondary
PHP Artisan make:event deleteevent
Writing events
#DeleteEvent.php
<?phpnamespace app\events;use app\events\event;use illuminate\queue\serializesmodels;use Illuminate\Contracts\ Broadcasting\shouldbroadcast;class Deleteevent extends event{use serializesmodels; Public function __construct () { // } public function Broadcaston () { print ' delete event '; }}
Creating a listening listener
Execute the following command, after execution completes, a deleteeventlistener.php file appears under App\listeners, which is the listener for event Deleteevent
PHP artisan make:listener--event=deleteevent Deleteeventlistener
Writing event listeners
#DeleteEventListener.php
<?phpnamespace app\listeners;use app\events\deleteevent;use illuminate\queue\interactswithqueue;use Illuminate\ Contracts\queue\shouldqueue;class deleteeventlistener{public function __construct () { // } Public function handle (deleteevent $event) { // $event->broadcaston ();} }
Invoke Event-the controller uses
#EventController.php
<?phpnamespace app\http\controllers;use app\events\deleteevent;use app\events\someevent;use Illuminate\Http\ Request;use app\http\requests;class Eventcontroller extends controller{ //Public Function index () {// Event (New Someevent ()); The framework defaults to calling Broadcaston () $event = new Deleteevent (); Custom Event ($event->broadcaston ());} }
Writing a route
#routes.php
Route::get ('/event ', [' uses ' = ' [email protected] ']);
Use cases for Laravel events