TicketsController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Http\Controllers\Mod;
  3. use App\Models\User;
  4. use App\Models\Ticket;
  5. use App\Models\Server;
  6. use App\Models\TicketCategory;
  7. use App\Models\TicketComment;
  8. use App\Http\Controllers\Controller;
  9. use Illuminate\Support\Facades\Cache;
  10. use Illuminate\Http\Request;
  11. use Illuminate\Support\Facades\Auth;
  12. use App\Notifications\Ticket\User\ReplyNotification;
  13. class TicketsController extends Controller
  14. {
  15. public function index() {
  16. $tickets = Ticket::paginate(10);
  17. $ticketcategories = TicketCategory::all();
  18. return view("admin.ticket.index", compact("tickets", "ticketcategories"));
  19. }
  20. public function show($ticket_id) {
  21. $ticket = Ticket::where("ticket_id", $ticket_id)->firstOrFail();
  22. $ticketcomments = $ticket->ticketcomments;
  23. $ticketcategory = $ticket->ticketcategory;
  24. $server = Server::where('id', $ticket->server)->first();
  25. return view("admin.ticket.show", compact("ticket", "ticketcategory", "ticketcomments", "server"));
  26. }
  27. public function close($ticket_id) {
  28. $ticket = Ticket::where("ticket_id", $ticket_id)->firstOrFail();
  29. $ticket->status = "Closed";
  30. $ticket->save();
  31. $ticketOwner = $ticket->user;
  32. return redirect()->back()->with('success', __('A ticket has been closed, ID: #') . $ticket->ticket_id);
  33. }
  34. public function delete($ticket_id){
  35. $ticket = Ticket::where("ticket_id", $ticket_id)->firstOrFail();
  36. TicketComment::where("ticket_id", $ticket->id)->delete();
  37. $ticket->delete();
  38. return redirect()->back()->with('success', __('A ticket has been deleted, ID: #') . $ticket_id);
  39. }
  40. public function reply(Request $request) {
  41. $this->validate($request, array("ticketcomment" => "required"));
  42. $ticket = Ticket::where('id', $request->input("ticket_id"))->firstOrFail();
  43. $ticket->status = "Answered";
  44. $ticket->update();
  45. $ticketcomment = TicketComment::create(array(
  46. "ticket_id" => $request->input("ticket_id"),
  47. "user_id" => Auth::user()->id,
  48. "ticketcomment" => $request->input("ticketcomment"),
  49. ));
  50. $user = User::where('id', $ticket->user_id)->firstOrFail();
  51. $newmessage = $request->input("ticketcomment");
  52. $user->notify(new ReplyNotification($ticket, $user, $newmessage));
  53. return redirect()->back()->with('success', __('Your comment has been submitted'));
  54. }
  55. }