I have multiple halls. I have to search halls for booking with given dates and time (morning or evening). If these dates and time(morning or evening) are available in any hall it will return all those halls which are available for booking.It will check all booking and return all those halls which are available on these dates and time. At the time of booking user can book 3 days like 25 to 28 .. In these dates 26 and 27 are not available dates. I hope you understand my scenario. I have other table "events" where all halls are added. I have to return all halls which are available on these dates. You can see in image i have posted... if i want to book dates from 20-02-2019 to 25-02-2019.. then it will return me event_id 2 details because it is available on these dates. I have issue with my query.
public function getAvailableEvents(Request $request)
{
try {
$allInputs = Input::all();
$categoryID = $request->input('category_id');
$startDate = $request->input('start_date');
$endDate = $request->input('end_date');
$time = $request->input('time');
$validation = Validator::make($allInputs, [
'category_id' => 'required',
'start_date' => 'required',
'end_date' => 'required',
'time' => 'required',
]);
if ($validation->fails()) {
DB::rollback();
return $response = (new apiresponse())->customResponse('Fields required!',
422,
$validation->errors()->toArray());
} else {
$getEvents = Booking::where('category_id', '=', $categoryID)
->where(function ($q) use ($endDate,$startDate,$time) {
$q->where('date_to','!=',$endDate)
->orWhere('date_from','!=',$startDate)
->orWhere('booking_time','!=',$time);
})->get();
if (count($getEvents) > 0) {
for ($i = 0; $i < count($getEvents); $i++) {
$data[] = array(
"booking_id" => $getEvents[$i]->id,
"ref_no" => $getEvents[$i]->ref_no,
"category_id" => $getEvents[$i]->category_id,
**"event_id" => $getEvents[$i]->event_id,**
"user_id" => $getEvents[$i]->user_id,
"phone" => $getEvents[$i]->phone,
"booking_status" => $getEvents[$i]->booking_status,
"type" => $getEvents[$i]->type,
"date_from" => $getEvents[$i]->date_from,
"date_to" => $getEvents[$i]->date_to,
"booking_time" => $getEvents[$i]->booking_time,
"price" => $getEvents[$i]->price,
"rating" => $getEvents[$i]->rating,
"date_time" => $getEvents[$i]->date_time ?? "",
);
}
return $response = (new apiresponse())->customResponse('Events found!',
200,
$data);
} else {
DB::rollback();
return $response = (new apiresponse())->customResponse(
'These dates are not available!',
422,
(object)[]);
}
}
} catch (\Illuminate\Database\QueryException $ex) {
return $response = (new apiresponse())->customResponse(
'Fail!',
422,
$ex);
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire