adminService = $adminService; $this->ticketRepository = $ticketRepository; } /** * Display a listing of the resource. */ public function index(Request $request) { $data['title'] = 'Ticket List'; $data['tickets'] = $this->ticketRepository->findAll(); $data['statusList'] = Ticket::STATUS; return view('pms::ticket.index', $data); } /** * Show the form for creating a new resource. */ public function create() { $data['title'] = 'Create Ticket'; $data['statusList'] = Ticket::STATUS; $data['priority'] = Ticket::PRIORITY; $data['ticketType'] = Ticket::TICKET_TYPE; $data['departmentList'] = $this->adminService->pluckDepartments(); return view('pms::ticket.create', $data); } /** * Store a newly created resource in storage. */ public function store(Request $request): RedirectResponse { $inputData = $request->all(); $ticket = $this->ticketRepository->create($inputData); if ($request->hasFile('file')) { $path = 'uploads/task'; $inputData['file'] = uploadImage($request->file, $path); $ticket->documents()->updateOrCreate([ 'documentable_id' => $ticket->id, 'documentable_type' => 'Modules\PMS\Models\Ticket', ], [ 'document_name' => 'Ticket Files', 'document_path' => $inputData['file'], ]); } toastr()->success('Ticket Created Succesfully'); return redirect()->route('ticket.index'); } /** * Show the specified resource. */ public function show($id) { $data['title'] = 'View Ticket'; $data['tickets'] = $this->ticketRepository->getTicketById($id); $data['status'] = Ticket::STATUS; $data['priority'] = Ticket::PRIORITY; $data['ticketType'] = Ticket::TICKET_TYPE; return view('pms::ticket.show', $data); } /** * Show the form for editing the specified resource. */ public function edit($id) { $data['title'] = 'Edit Ticket'; $data['ticket'] = $this->ticketRepository->getTicketById($id); return view('pms::ticket.edit', $data); } /** * Update the specified resource in storage. */ public function update(Request $request, $id): RedirectResponse { $inputData = $request->except(['_method', '_token']); try { $this->ticketRepository->update($id, $inputData); toastr()->success('Ticket Update Succesfully'); } catch (\Throwable $th) { toastr()->error($th->getMessage()); } return redirect()->route('ticket.index'); } /** * Remove the specified resource from storage. */ public function destroy($id) { try { $this->ticketRepository->delete($id); toastr()->success('Ticket Deleted Succesfully'); } catch (\Throwable $th) { toastr()->error($th->getMessage()); } } public function storeComment(Request $request) { $request->validate([ 'content' => 'required', ]); $ticket = $this->ticketRepository->getTicketById($request->tickets_id); $ticket->comments()->create(['content' => $request->content, 'comment_by' => Auth::id()]); return redirect()->back(); } public function uploadFile(Request $request) { $task = $this->ticketRepository->getTicketById($request->task_id); if ($request->hasFile('file')) { $path = 'uploads/ticket1'; $fileName = $request->file->getClientOriginalName(); $filePath = uploadImage($request->file, $path); $task->documents()->create(['document_name' => $fileName, 'document_path' => $filePath]); } return response()->json([ 'status' => true, 'msg' => 'File Upload', ], 200); } public function changeStatus(Request $request) { try { $taskModel = $this->ticketRepository->getTicketById($request->id); $taskModel->status = $request->changeStatus; $taskModel->save(); return response()->json([ 'status' => true, 'msg' => 'Status Changed', ], 200); } catch (\Throwable $th) { return response()->json([ 'status' => false, 'msg' => $th->getMessage(), ], 400); } } }