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.

74 lines
2.7 KiB

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Appointment;
use Carbon\Carbon;
2 years ago
use App\Models\AppointmentBookingDetail;
class AppointmentController extends Controller
{
public function index(){
$educationAppointments = Appointment::where('service_type', '1')->get();
$visaAppointments = Appointment::where('service_type', '2')->get();
// foreach($educationAppointments as $appointment){
// $startTime = Carbon::createFromFormat('H:i', $appointment->start_time);
// $date = Carbon::createFromFormat('H:i', $appointment->start_time);
// dd($date);
// }
return view('appointment', compact('educationAppointments', 'visaAppointments'));
}
public function get_appointment_by_date(Request $request){
$dateTime = $request->date;
$date_parts = explode(" ", $dateTime);
$month_number = date_parse($date_parts[1])['month'];
$carbon = Carbon::createFromDate($date_parts[3], $month_number, $date_parts[2]);
$date = $carbon->format('Y-m-d');
2 years ago
$appointments = Appointment::whereDate('date',$date)->where(['status' => 1, 'is_booked' => false])->get();
// $users = DB::table('appointments')->whereDate('created_at', '2022-12-01')->get();
// $time = [];
// foreach($appointments as $appointment){
// array_push($time, [$appointment->start_time, $appointment->id]);
// }
// dd($time);
return response()->json(['appointment' => $appointments]);
2 years ago
}
public function form_submit(Request $request){
$request->validate([
'name' => 'required',
'email' => 'required|email',
'phone' => 'required',
]);
$appointment_detail = new AppointmentBookingDetail();
$appointment_detail->name = $request->get('name');
$appointment_detail->email = $request->get('email');
$appointment_detail->phone = $request->get('phone');
$appointment_detail->notes = $request->get('notes');
$appointment_id = $request->get('appointment_id');
$appointment_detail->appointment_id = $appointment_id;
if($appointment_detail->save()){
$appointment = Appointment::findorfail($appointment_id);
2 years ago
$date = Carbon::createFromFormat('Y-m-d', $appointment->date);
$formated_date = $date->format('M d, Y');
// $isAm = ($appointment['start_time'] < '12:00:00') ? 'AM' :'PM';
2 years ago
$appointment->is_booked = true;
$appointment->save();
}
2 years ago
return response()->json(['appointment_detail' => $appointment_detail,'appointment' => $appointment,'formated_date' => $formated_date],200);
2 years ago
}
}