107 lines
2.8 KiB
PHP
107 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Modules\Appointment\app\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Modules\Appointment\app\Repositories\AppointmentRepository;
|
|
use Modules\Appointment\app\Http\Requests\CreateAppointmentRequest;
|
|
|
|
class AppointmentController extends Controller
|
|
{
|
|
protected $appointmentRepository;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->appointmentRepository = new AppointmentRepository;
|
|
}
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
$perPage = $request->has('per-page') ? $request->input('per-page') : null;
|
|
$filter = $request->has('filter') ? $request->input('filter') : [];
|
|
$data['appointments'] = $this->appointmentRepository->allAppointmentList($perPage, $filter);
|
|
|
|
$data['appointmentCount'] = $data['appointments']->count();
|
|
return view('appointment::index', $data);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
return view('appointment::create');
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(CreateAppointmentRequest $request): RedirectResponse
|
|
{
|
|
try {
|
|
$validated = $request->validated();
|
|
$this->appointmentRepository->storeAppointmentList($validated);
|
|
|
|
return redirect("/thankyou")->with('success','Message Sent Successfully');
|
|
|
|
} catch (\Throwable $th) {
|
|
report($th);
|
|
toastr()->error('Something went wrong.');
|
|
return back();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Show the specified resource.
|
|
*/
|
|
public function show($uuid)
|
|
{
|
|
$data['appointment'] = $this->appointmentRepository->findAppointmentListById($uuid);
|
|
return view('appointment::show', $data);
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
return view('appointment::edit');
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, $id): RedirectResponse
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy($uuid)
|
|
{
|
|
try {
|
|
$appointment = $this->appointmentRepository->deleteAppointmentList($uuid);
|
|
|
|
if (!$appointment) {
|
|
toastr()->error('Appointment not found.');
|
|
return back();
|
|
}
|
|
|
|
toastr()->success('Appointment deleted successfully.');
|
|
|
|
return redirect()->route('cms.appointment.index');
|
|
} catch (\Throwable $th) {
|
|
report($th);
|
|
toastr()->error('Something went wrong.');
|
|
return back();
|
|
}
|
|
}
|
|
}
|