예제 #1
0
 public function show(Ticket $ticket)
 {
     if (!Entrust::can('view_ticket')) {
         return redirect('/dashboard')->withErrors(config('constants.NA'));
     }
     if (!Entrust::hasRole('admin')) {
         $ticket = $ticket->with('assignedUser')->whereId($ticket->id)->whereHas('assignedUser', function ($query) {
             $query->where('user_id', '=', Auth::user()->id);
         })->first();
     }
     if (!$ticket) {
         return redirect('/ticket')->withErrors('You cannot access a ticket without permission.');
     }
     $departments = Department::lists('department_name', 'id')->all();
     $ticket_types = TicketType::lists('ticket_type_name', 'id')->all();
     $priorities = config('list.priority');
     $ticket_status = config('list.ticket_status');
     $comments = \App\Comment::whereBelongsTo('ticket')->whereUniqueId($ticket->id)->get();
     $note = \App\Note::whereBelongsTo('ticket')->whereUniqueId($ticket->id)->first();
     $attachments = \App\Attachment::whereBelongsTo('ticket')->whereUniqueId($ticket->id)->get();
     $ticket_array = $ticket->toArray();
     $users = User::with('roles')->whereHas('roles', function ($query) {
         $query->where('roles.name', '!=', 'user');
     })->lists('name', 'id')->all();
     $ticket_with_user = $ticket->whereId($ticket->id)->with('assignedUser')->first();
     $selected_users = array();
     foreach ($ticket_with_user->assignedUser as $user) {
         $selected_users[] = $user->id;
     }
     $custom_field_values = Helper::getCustomFieldValues($this->form, $ticket->id);
     $template_list = array();
     $templates = Helper::getTemplate();
     foreach ($templates as $key => $template) {
         if ($key != 'forgot_password' && $template['category'] == 'ticket') {
             $template_list[$key] = $template['title'];
         }
     }
     return view('ticket.show', compact('ticket', 'departments', 'ticket_types', 'priorities', 'users', 'selected_users', 'ticket_with_user', 'ticket_array', 'ticket_status', 'comments', 'note', 'attachments', 'custom_field_values', 'template_list'));
 }