appointment-book

suman
Mahesh Sharma 2 years ago
parent 77299944de
commit 7178c37eba
  1. 31
      app/Http/Controllers/AppointmentController.php
  2. 4
      app/Models/Appointment.php
  3. 15
      app/Models/AppointmentBookingDetail.php
  4. 32
      database/migrations/2023_02_08_105304_add_is_booked_to_appointments_table.php
  5. 37
      database/migrations/2023_02_08_105817_create_appointment_booking_details_table.php
  6. 33
      resources/views/appointment.blade.php
  7. 4
      resources/views/blogs.blade.php
  8. 1
      routes/web.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);
}
}

@ -10,4 +10,8 @@ class Appointment extends Model
use HasFactory;
protected $guarded = ['id'];
public function appointment_booking_detail(){
return $this->hasOne(AppointmentBookingDetail::class);
}
}

@ -0,0 +1,15 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class AppointmentBookingDetail extends Model
{
use HasFactory;
public function appointment(){
return $this->belongsTo(Appointment::class);
}
}

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('appointments', function (Blueprint $table) {
$table->boolean('is_booked')->default(false);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('appointments', function (Blueprint $table) {
//
});
}
};

@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('appointment_booking_details', function (Blueprint $table) {
$table->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');
}
};

@ -62,28 +62,29 @@
</div>
<div class="modal-body">
<!-- Form with the fields name, email, phone, and notes -->
<form>
<form id = "appointment-form">
<input type="hidden" name="appointment_id" id="appointment_id">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" required>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" required>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="form-group">
<label for="phone">Phone</label>
<input type="tel" class="form-control" id="phone" required>
<input type="tel" class="form-control" id="phone" name="phone" required>
</div>
<div class="form-group">
<label for="notes">Notes</label>
<textarea class="form-control" id="notes"></textarea>
<textarea class="form-control" id="notes" name = "notes"></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Book Appointment</button>
<button type="button" onclick = "submitAppointment(event) " class="btn btn-primary">Book Appointment</button>
</div>
</div>
</div>
@ -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);
});
@ -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.
}
});
}
</script>
@endsection

@ -37,7 +37,7 @@
@php $date = Carbon\Carbon::createFromFormat('Y-m-d', $blog->publish_date);@endphp
<h6>{{$date->format('j M, Y')}}</h6>
<h2>{{$blog->title}} </h2>
<p>{!!(\Illuminate\Support\Str::limit($blog->description, 200, $end='...'))!!}</p>
{!!(\Illuminate\Support\Str::limit($blog->description, 200, $end='...'))!!}</p>
<a href="{{url('/blog/'.$blog->slug)}}">Read More <i class="fa-solid fa-arrow-right-long ms-2 fa-sm"></i></a>
</div>
</div>
@ -53,7 +53,7 @@
<h3>Study in Australia</h3>
<h6>{{$blog->publish_date}}</h6>
<h2>{{$blog->title}} </h2>
<p>{!!(\Illuminate\Support\Str::limit($blog->description, 200, $end='...'))!!}</p>
{!!(\Illuminate\Support\Str::limit($blog->description, 200, $end='...'))!!}</p>
<a href="{{url('/blog/'.$blog->slug)}}">Read More <i class="fa-solid fa-arrow-right-long ms-2 fa-xs"></i></a>
</div>
</div>

@ -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');

Loading…
Cancel
Save