123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace App\Http\Controllers\Seller;
- use App\Mail\SupportMailManager;
- use Illuminate\Http\Request;
- use App\Models\Ticket;
- use App\Models\TicketReply;
- use App\Models\User;
- use Auth;
- use Mail;
- class SupportTicketController extends Controller
- {
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function index()
- {
- $tickets = Ticket::where('user_id', Auth::user()->id)->orderBy('created_at', 'desc')->paginate(9);
- return view('seller.support_ticket.index', compact('tickets'));
- }
- /**
- * Store a newly created resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function store(Request $request)
- {
- $ticket = new Ticket;
- $ticket->code = max(100000, (Ticket::latest()->first() != null ? Ticket::latest()->first()->code + 1 : 0)).date('s');
- $ticket->user_id = Auth::user()->id;
- $ticket->subject = $request->subject;
- $ticket->details = $request->details;
- $ticket->files = $request->attachments;
- if($ticket->save()){
- $this->send_support_mail_to_admin($ticket);
- flash(translate('Ticket has been sent successfully'))->success();
- return redirect()->route('seller.support_ticket.index');
- }
- else{
- flash(translate('Something went wrong'))->error();
- }
- }
- public function send_support_mail_to_admin($ticket){
- $array['view'] = 'emails.support';
- $array['subject'] = 'Support ticket Code is:- '.$ticket->code;
- $array['from'] = env('MAIL_FROM_ADDRESS');
- $array['content'] = 'Hi. A ticket has been created. Please check the ticket.';
- $array['link'] = route('support_ticket.admin_show', encrypt($ticket->id));
- $array['sender'] = $ticket->user->name;
- $array['details'] = $ticket->details;
- try {
- Mail::to(User::where('user_type', 'admin')->first()->email)->queue(new SupportMailManager($array));
- } catch (\Exception $e) {
- // dd($e->getMessage());
- }
- }
- /**
- * Display the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function show($id)
- {
- $ticket = Ticket::findOrFail(decrypt($id));
- $ticket->client_viewed = 1;
- $ticket->save();
- $ticket_replies = $ticket->ticketreplies;
- return view('seller.support_ticket.show', compact('ticket','ticket_replies'));
- }
- public function ticket_reply_store(Request $request)
- {
- $ticket_reply = new TicketReply;
- $ticket_reply->ticket_id = $request->ticket_id;
- $ticket_reply->user_id = $request->user_id;
- $ticket_reply->reply = $request->reply;
- $ticket_reply->files = $request->attachments;
- $ticket_reply->ticket->viewed = 0;
- $ticket_reply->ticket->status = 'pending';
- $ticket_reply->ticket->save();
- if($ticket_reply->save()){
- flash(translate('Reply has been sent successfully'))->success();
- return back();
- }
- else{
- flash(translate('Something went wrong'))->error();
- }
- }
- }
|