/** * Creates new Ticket and redirects to its page * * @return \Illuminate\Http\RedirectResponse * @throws \ValidationException */ public function onTicketCreate() { $data = post(); $this->helpers->validateTicket($data); $creator = \Auth::getUser(); $ticketPage = Settings::get('address'); $newStatus = TicketStatus::where('name', 'New')->first()->id; $content = $this->purifyTicket($data['content']); $ticket = new Ticket(); $ticket->hash_id = 'temp'; $ticket->category_id = $data['category']; $ticket->creator_id = $creator->id; $ticket->email = $creator->email; $ticket->website = $data['website']; $ticket->topic = $data['topic']; $ticket->content = $content; $ticket->status = $newStatus; $ticket->save(); $hashId = $this->helpers->generateHashId($ticket->id); $ticket->hash_id = $hashId; $ticket->save(); $this->page['hash_id'] = $hashId; $this->helpers->newTicketHandler($hashId); $mailer = new SupportMailer(); $address = Settings::get('address'); $vars = ['ticket_number' => $ticket->hash_id, 'ticket_link' => $address . '/' . $ticket->hash_id]; $mailer->sendAfterTicketCreated($creator->email, $vars); return \Redirect::to($ticketPage . $hashId); }
/** * After create method * * Changes temporary hash id to proper basing on a record id */ public function afterCreate() { if ($this->hash_id == 'invalid') { $helpers = new SupportHelpers(); $hashId = $helpers->generateHashId($this->id); $this->hash_id = $hashId; $this->save(); } }