From 7178c37ebaa35f2ea01c127fdb792107b3920a31 Mon Sep 17 00:00:00 2001 From: Mahesh Sharma Date: Wed, 8 Feb 2023 17:20:21 +0545 Subject: [PATCH] appointment-book --- .../Controllers/AppointmentController.php | 31 +++++++++++++- app/Models/Appointment.php | 4 ++ app/Models/AppointmentBookingDetail.php | 15 +++++++ ...04_add_is_booked_to_appointments_table.php | 32 +++++++++++++++ ...eate_appointment_booking_details_table.php | 37 +++++++++++++++++ resources/views/appointment.blade.php | 41 ++++++++++++++----- resources/views/blogs.blade.php | 4 +- routes/web.php | 1 + 8 files changed, 151 insertions(+), 14 deletions(-) create mode 100644 app/Models/AppointmentBookingDetail.php create mode 100644 database/migrations/2023_02_08_105304_add_is_booked_to_appointments_table.php create mode 100644 database/migrations/2023_02_08_105817_create_appointment_booking_details_table.php diff --git a/app/Http/Controllers/AppointmentController.php b/app/Http/Controllers/AppointmentController.php index c533a93..296a50d 100644 --- a/app/Http/Controllers/AppointmentController.php +++ b/app/Http/Controllers/AppointmentController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Appointment; use Carbon\Carbon; +use App\Models\AppointmentBookingDetail; class AppointmentController extends Controller { @@ -29,7 +30,7 @@ class AppointmentController extends Controller $date = $carbon->format('Y-m-d'); - $appointments = Appointment::whereDate('date',$date)->where('status',1)->get(); + $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){ @@ -37,5 +38,33 @@ class AppointmentController extends Controller // } // dd($time); return response()->json(['appointment' => $appointments]); + } + + 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); + $appointment->is_booked = true; + $appointment->save(); + } + + return response()->json(['appointment' => $appointment_detail],200); + + + + } } diff --git a/app/Models/Appointment.php b/app/Models/Appointment.php index 408a7c5..6d68f1b 100644 --- a/app/Models/Appointment.php +++ b/app/Models/Appointment.php @@ -10,4 +10,8 @@ class Appointment extends Model use HasFactory; protected $guarded = ['id']; + + public function appointment_booking_detail(){ + return $this->hasOne(AppointmentBookingDetail::class); + } } diff --git a/app/Models/AppointmentBookingDetail.php b/app/Models/AppointmentBookingDetail.php new file mode 100644 index 0000000..4645922 --- /dev/null +++ b/app/Models/AppointmentBookingDetail.php @@ -0,0 +1,15 @@ +belongsTo(Appointment::class); + } +} diff --git a/database/migrations/2023_02_08_105304_add_is_booked_to_appointments_table.php b/database/migrations/2023_02_08_105304_add_is_booked_to_appointments_table.php new file mode 100644 index 0000000..2b1f558 --- /dev/null +++ b/database/migrations/2023_02_08_105304_add_is_booked_to_appointments_table.php @@ -0,0 +1,32 @@ +boolean('is_booked')->default(false); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('appointments', function (Blueprint $table) { + // + }); + } +}; diff --git a/database/migrations/2023_02_08_105817_create_appointment_booking_details_table.php b/database/migrations/2023_02_08_105817_create_appointment_booking_details_table.php new file mode 100644 index 0000000..32094c0 --- /dev/null +++ b/database/migrations/2023_02_08_105817_create_appointment_booking_details_table.php @@ -0,0 +1,37 @@ +id(); + $table->bigInteger('appointment_id')->unsigned(); + $table->foreign('appointment_id')->references('id')->on('appointments')->onDelete('cascade'); + $table->string('name'); + $table->string('email')->nullable(); + $table->string('phone'); + $table->string('notes')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('appointment_booking_details'); + } +}; diff --git a/resources/views/appointment.blade.php b/resources/views/appointment.blade.php index d354193..8df1652 100644 --- a/resources/views/appointment.blade.php +++ b/resources/views/appointment.blade.php @@ -62,28 +62,29 @@ @@ -131,7 +132,6 @@ }); - var dates = [7, 8, 9] var availableDates = document.getElementById('available-dates') $calender.on('zabuto:calendar:day', function (e) { @@ -178,7 +178,9 @@ var appointmentId = $(this).data("appointment-id"); $("#modal").attr("id", "modal-" + appointmentId); + $('#appointment-form input[name="appointment_id"]').val(appointmentId); $("#modal-" + appointmentId).modal("show"); + // showAppointmentForm(appointmentId); }); @@ -191,10 +193,10 @@ function showAppointmentForm(appointmentId){ - // $("#appointmentModal").modal(); - //show Appointment booking form - // Reset the form - // $('#appointment-form')[0].reset(); + // $("#appointmentModal").modal(); + //show Appointment booking form + // Reset the form + // $('#appointment-form')[0].reset(); // Store the appointment ID in a hidden field // $('#appointment-form input[name="appointment_id"]').val(appointmentId); @@ -204,5 +206,22 @@ } + function submitAppointment(event){ + event.preventDefault(); + $.ajax({ + url: "/appointment_submit", + type: "post", + data: $("form").serialize(), + success: function(response) { + console.log(response.appointment_detail); + // Handle the success response + // e.g. close the modal, show a success message, etc. + } + }); + + } + + + @endsection \ No newline at end of file diff --git a/resources/views/blogs.blade.php b/resources/views/blogs.blade.php index 1fc7331..ea8bebc 100644 --- a/resources/views/blogs.blade.php +++ b/resources/views/blogs.blade.php @@ -37,7 +37,7 @@ @php $date = Carbon\Carbon::createFromFormat('Y-m-d', $blog->publish_date);@endphp
{{$date->format('j M, Y')}}

{{$blog->title}}

-

{!!(\Illuminate\Support\Str::limit($blog->description, 200, $end='...'))!!}

+ {!!(\Illuminate\Support\Str::limit($blog->description, 200, $end='...'))!!}

Read More @@ -53,7 +53,7 @@

Study in Australia

{{$blog->publish_date}}

{{$blog->title}}

-

{!!(\Illuminate\Support\Str::limit($blog->description, 200, $end='...'))!!}

+ {!!(\Illuminate\Support\Str::limit($blog->description, 200, $end='...'))!!}

Read More diff --git a/routes/web.php b/routes/web.php index 52aa036..95bea7c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -71,6 +71,7 @@ Route::post('contact', [ContactController::class,'post_contact']); Route::get('about', [FrontendAboutUsController::class,'index']); Route::get('appointment', [FrontendAppointmentController::class,'index']); Route::post('appointments_by_date', [FrontendAppointmentController::class,'get_appointment_by_date']); +Route::post('appointment_submit', [FrontendAppointmentController::class,'form_submit']); // Route::get('/about', function () { // return view('about');