You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
5.2 KiB

2 years ago
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Appointment;
use Illuminate\Http\Request;
use Carbon\Carbon;
2 years ago
class AppointmentController extends Controller
{
protected $view = 'admin.appointment.';
2 years ago
protected $redirect = 'admin/appointments';
// protected $service;
2 years ago
public function education_appointments()
{
$appointments = Appointment::where('service_type', '1')->orderBy('id', 'DESC');
if (\request('date')) {
$date = \request('date');
$appointments = $appointments->whereDate('date', $date);
}
if (\request('status')) {
$status = \request('status');
$appointments = $appointments->where('status', $status);
2 years ago
}
if (\request('is_booked')) {
$is_booked = (\request('is_booked')) == '1' ? true : false;
$appointments = $appointments->where('is_booked', $is_booked);
2 years ago
}
$appointments = $appointments->paginate(20);
$service = 'Education';
$is_booked = $is_booked ?? null;
$date = $date ?? null;
$status = $status ?? null;
return view($this->view . 'index', compact('appointments', 'service', 'is_booked', 'date', 'status'));
}
public function visa_appointments()
{
$appointments = Appointment::where('service_type', '2')->orderBy('id', 'DESC');
if (\request('date')) {
$date = \request('date');
$appointments = $appointments->whereDate('date', $date);
}
if (\request('status')) {
$status = \request('status');
$appointments = $appointments->where('status', $status);
}
if (\request('is_booked')) {
$is_booked = (\request('is_booked')) == '1' ? true : false;
$appointments = $appointments->where('is_booked', $is_booked);
}
$appointments = $appointments->paginate(20);
$is_booked = $is_booked ?? null;
$date = $date ?? null;
$status = $status ?? null;
$service = 'Migration|Visa';
return view($this->view . 'index', compact('appointments', 'service', 'is_booked', 'date', 'status'));
2 years ago
}
public function create()
{
return view($this->view . 'create');
2 years ago
}
public function store(Request $request)
{
$request->validate([
'date' => 'required|date',
'start_time' => 'required|date_format:H:i',
'end_time' => 'required|date_format:H:i',
2 years ago
// 'location' => 'required|max:255',
// 'description' => 'required',
]);
$start_time = Carbon::createFromFormat('H:i', $request->get('start_time'))->format('H:i A');
$end_time = Carbon::createFromFormat('H:i', $request->get('end_time'))->format('H:i A');
2 years ago
$appointment = new Appointment([
'date' => $request->get('date'),
'start_time' => $start_time,
'end_time' => $end_time,
2 years ago
'location' => $request->get('location'),
'description' => $request->get('description'),
'service_type' => $request->get('service_type'),
2 years ago
]);
$appointment->save();
return redirect($this->redirect)->with('success', 'Appointment has been added');
}
public function edit($id)
{
$appointment = Appointment::findorfail($id);
$start_time = explode(" ", $appointment->start_time);
$start_time = $start_time[0];
2 years ago
$end_time = explode(" ", $appointment->end_time);
$end_time = $end_time[0];
$appointment['start_time'] = $start_time;
$appointment['end_time'] = $end_time;
return view($this->view . 'edit', compact('appointment'));
2 years ago
}
public function update(Request $request, $id)
{
$request->validate([
'date' => 'required|date',
'start_time' => 'required|date_format:H:i',
'end_time' => 'required|date_format:H:i',
2 years ago
// 'location' => 'required|max:255',
// 'description' => 'required',
]);
$start_time = Carbon::createFromFormat('H:i', $request->get('start_time'))->format('H:i A');
$end_time = Carbon::createFromFormat('H:i', $request->get('end_time'))->format('H:i A');
2 years ago
$appointment = Appointment::find($id);
$appointment->date = $request->get('date');
$appointment->start_time = $start_time;
$appointment->end_time = $end_time;
2 years ago
$appointment->location = $request->get('location');
$appointment->description = $request->get('description');
$appointment->service_type = $request->get('service_type');
$appointment->status = $request->get('status');
2 years ago
$appointment->save();
return redirect($this->redirect)->with('success', 'Appointment has been updated');
}
public function show($id)
{
2 years ago
$appointment = Appointment::with('appointment_booking_detail')->findorfail($id);
return view($this->view . 'show', compact('appointment'));
2 years ago
}
2 years ago
public function destroy($id)
{
$appointment = Appointment::find($id);
$appointment->delete();
return redirect($this->redirect)->with('success', 'Appointment has been deleted');
}
}