88 lines
2.7 KiB
PHP
88 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\TicketReplyRequest;
|
|
use App\Models\TicketReply;
|
|
use App\Repositories\Ticket\TicketRepositoryInterface;
|
|
use App\Repositories\TicketReply\TicketReplyRepositoryInterface;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Mockery\Exception;
|
|
|
|
class SupportController extends Controller
|
|
{
|
|
public function __construct(
|
|
public TicketRepositoryInterface $ticketRepository,
|
|
public TicketReplyRepositoryInterface $ticketReplyRepository
|
|
) {}
|
|
public function index(Request $request)
|
|
{
|
|
|
|
$tickets = $this->ticketRepository->filter($request->merge(['page' => $request->get('1') ?? 1])->all());
|
|
$title = "All Support Ticket";
|
|
return view('administrator.pages.support.index', compact('title', 'tickets'));
|
|
}
|
|
|
|
public function edit(int $ticket_num = 0)
|
|
{
|
|
|
|
$ticket = $this->ticketRepository->findWithRelationshipsByKey('ticket_num', $ticket_num, [
|
|
'reply.user',
|
|
'customer'
|
|
]);
|
|
|
|
if (! $ticket) {
|
|
return back()->withErrors('Invalid Request');
|
|
}
|
|
|
|
$title = "Ticket #" . $ticket_num;
|
|
|
|
return view("administrator.pages.support.view", compact('title', 'ticket'));
|
|
}
|
|
|
|
public function reply(int $id = 0, TicketReplyRequest $request)
|
|
{
|
|
|
|
$ticket = $this->ticketRepository->find($id);
|
|
if (! $ticket) {
|
|
return back()->withInput()->withErrors('Invalid Request');
|
|
}
|
|
$request->validated();
|
|
|
|
$request->merge(['user_id' => auth()->guard('admin')->id()]);
|
|
|
|
DB::beginTransaction();
|
|
try {
|
|
$this->ticketReplyRepository->create($request->all());
|
|
$this->ticketRepository->updateBy('ticket_num',$ticket->ticket_num,['status' => 1]);
|
|
DB::commit();
|
|
} catch (Exception $error) {
|
|
DB::rollBack();
|
|
return back()->withInput()->withErrors($error->getMessage());
|
|
}
|
|
return back()->with('success', 'Reply successfully');
|
|
}
|
|
public function close(int $ticket_num = 0)
|
|
{
|
|
|
|
$ticket = $this->ticketRepository->findBy('ticket_num', $ticket_num);
|
|
|
|
if (! $ticket) {
|
|
return back()->withErrors('Invalid Request');
|
|
}
|
|
|
|
DB::beginTransaction();
|
|
try {
|
|
$this->ticketRepository->updateBy('ticket_num',$ticket_num,['status' => 0]);
|
|
DB::commit();
|
|
} catch (Exception $error) {
|
|
DB::rollBack();
|
|
return back()->withInput()->withErrors($error->getMessage());
|
|
}
|
|
return redirect()->route('support.index')->with('success', 'Closed successfully');
|
|
}
|
|
}
|