Posts

Showing posts from February, 2019

Laravel Event Listener for keeping history

App\Providers\EventServiceProvider.php protected $listen = [     'App\Events\ResolveHistoryEvent'=>[         'App\Listeners\ResolveHistoryEventListener'     ] ]; php artisan event:generate App\Modules\Tickets\Controllers\TicketsController.php public function reopenTicket($ticketId){     $ticket = Tickets::find($ticketId);     $ticket->resolve_status = 2;     $ticket->reopen_time = Carbon::now();     $ticket->save();     event(new ResolveHistoryEvent($ticket));     return redirect('tickets/active-list')->with('flash_success','Ticket reopen successfully!'); } App\Events\ResolveHistoryEvent.php public $resolveHistory; public function __construct($ticket) {     $this->resolveHistory = $ticket; } App\Listeners\ResolveHistoryEventListener.php public function recordTicketResolveHistory($ticket){     $resolveHistory = new TicketsResolveHistory();     $resolveHistory->ticket_id = $tic