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 @@
{!!(\Illuminate\Support\Str::limit($blog->description, 200, $end='...'))!!}
+ {!!(\Illuminate\Support\Str::limit($blog->description, 200, $end='...'))!!} Read More @@ -53,7 +53,7 @@{!!(\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');