Events

What are events?

Events are user-defined , allowing you to execute a code within the life-cycle of the specified events

You can define your own events on

app/Providers/CustomEventsServiceProvider.php

You can place your code inside boot() function.

You can see an example of already-defined functioning events in app/Providers/SystemEventsServiceProvider.php file


Example of an event: user.created :  


Event::listen('user.created', function($id,$email,$name,$verified){
	
	$data['name'] = $name;

	Mail::send('emails.users.welcome', $data, function($message) use ($email)
	{
		$message->from("noreply@example.com", "Support System");
		$message->to($email)->subject("Welcome to our website");
	});

	
});

The above code will send a new email to the , when a "new user" is created , or in another words when event user.created is fired.

You can also notice that the above event passes the variables $id,$email,$name,$verified. Each event will have different variables associated with it.

What are other types of events?

Here's a list of all events:

                                                                   
EventVariablesDescription

Users

user.created $id,$email,$name,$verified When a new user is created
user.verified $id When a new user verifies his email
user.resetrequest $id When a user requests a reset for his password  
user.loggedin $id When a user logs in
user.loggedout $id When a user logs out
user.updateprofile $id When a user updates his profile
user.updatedpreferences $id When a user updates his preferences
user.passwordchanged $id When a user changes his password

Tickets

ticket.created $id,$title,$user_id,$assigned_to,$department_id,$status When a new ticket is created
ticket.newmessage $id,$ticket_id,$user_id,$content,$type When a new message is posted on the ticket, form staff or user
ticket.autoclosed $ticket_id,$user_id When a ticket is automatically closed due to no response from the user in a while
ticket.closed $ticket_id,$user_id When a ticket is closed/solved

Live Chat

live.initiated $id,$user_id,$ip,$conversation,$description When a live chat is initiated/requested
live.unavailable $id,$user_id,$ip,$conversation,$description When a live chat is unavailable, due to no staff being online
live.ring $conversation_id,$agent_id When a staff ( agent ) is chosen to be assigned to the live chat
live.started $conversation_id When live chat starts
live.missed $conversation_id When live chat is missed due to no staff answering though online
live.closed $conversation_id When a live chat ends
live.newmessage $id,$conversation_id,$user_id,$content,$type When a new message or file is posted on a live chat

Emails

email.received $id,$from,$to,$subject,$content,$user When a new email is received, requires "Allow email replies" to be set-up
email.sent $id,$from,$to,$subject,$content,$user When a new email is sent

Anything else i should know about events?

You can also execute an event when on a whole type of events, like:


Event::listen('ticket.*', function($param){
	// Do something whenever there is a ticket action
	// Also you can get the exact event being fired using Event::firing() 
});