Ejemplo n.º 1
0
 public function store(Request $request)
 {
     $file = new TicketReplyFile();
     $file->fill($request->all());
     $file->save();
     return $file;
 }
Ejemplo n.º 2
0
 public function reply(Request $request, Ticket $ticket)
 {
     $input = $request->all();
     if ($input['submit'] == 'reply') {
         $data = ['user_id' => user()->id, 'body' => $request->input('body'), 'owner_type' => 'users', 'owner_id' => user()->id, 'ticket_id' => $ticket->id];
         $reply = TicketReply::create($data);
         if (!empty($input['files'])) {
             $files = TicketReplyFile::where('id', $input['files'])->get();
             $reply->files()->saveMany($files);
         }
         if ($ticket->open == 0) {
             $ticket->open = 1;
             $ticket->save();
         }
         // temp for order
         // dd($ticket->student_id);
         // $student = Student::with('department')->find($ticket->student_id);
         //$ticket->department_id = 11 + $student->department->term->year->id;
         $ticket->priority = 'low';
         $ticket->save();
         //end
         $ticket->replies()->save($reply);
         event(new UserRepliedToTicket($reply, $ticket->student_id));
         event(new UserSeenTicket($ticket->id, $ticket->student_id));
         if ($request->ajax()) {
             $ticket->load('replies', 'replies.owner', 'replies.files', 'replies.student', 'replies.user');
             foreach ($ticket->replies as $reply) {
                 if (!empty($reply->student_id)) {
                     $reply->seen = 1;
                     $reply->save();
                 }
             }
             return response()->json(['view' => view('tickets::tickets._replies', compact('ticket'))->render()]);
         }
         $message = trans('tickets::tickets.create_reply_success');
     } elseif ($input['submit'] == 'close') {
         $ticket->open = 0;
         $ticket->save();
         $message = trans('tickets::tickets.ticket_closed_success');
         return redirect()->route('tickets.tickets.index')->with('success', $message);
     } elseif ($input['submit'] == 'transferButton') {
         if (!empty($input['department_id'])) {
             $data['department_id'] = $input['department_id'];
             $data['comment'] = $input['comment'];
         }
         if (isset($data['ticket_category_id']) and $data['ticket_category_id'] == $ticket->ticket_category_id) {
             unset($data['ticket_category_id']);
         }
         if (isset($data['department_id']) && !empty($data['department_id'])) {
             //inser in ticket_comments
             $descriptions[] = trans('tickets::tickets.histories.department_changed', ['user' => user()->name, 'old' => $ticket->department->name, 'new' => TicketDepartment::find($data['department_id'])->name, 'comment' => $data['comment']]);
         }
         if (!empty($data)) {
             event(new TicketUpdated($ticket, $descriptions));
             if (!$ticket->fill($data)->save()) {
                 return $ticket->errors();
             }
         }
         $message = trans('tickets::tickets.bulk_update_success');
         return redirect()->route('tickets.tickets.index')->with('success', $message);
     }
     return redirect()->back()->with('success', $message);
 }