简体   繁体   中英

Laravel 5.4 orWhereBetween query not working properly returns no data

Hi i have this query which i want the result to be displayed. Now i have a date here that inputs date. When the data is being passed it returns an empty array. But when the data is static the results will display. Here is my script below

<form action="{{ action('TotalSaleController@searchConfirmed') }}" method="post">
                {{ csrf_field() }}
            <p class="mb-3 mb-lg-0">Search for all confirmed booking(s)</p>
            <select name="searchGuests" data-style="btn-selectpicker" title="Search Guest(s)" class="selectpicker form-control" data-live-search="true" >
                @foreach($getBookingGuests as $getBookingGuest)
                        <option value="{{ $getBookingGuest['first_name'] }}-{{ $getBookingGuest['last_name'] }} ">{{ $getBookingGuest['first_name'] }}, {{ $getBookingGuest['last_name'] }}</option>
                    @endforeach
            </select>
            <br>
            <br>
             <select name="searchPayment" data-style="btn-selectpicker" title="Search Payment(s)" class="selectpicker form-control" data-live-search="true" >
                    <option value="gcash">Gcash</option>
                    <option value="palawan">Palawan</option>
                    <option value="bpi">BPI</option>
              </select>
              <br>
              <br>
              <select name="searchRooms" data-style="btn-selectpicker" title="Search Room(s)" class="selectpicker form-control" data-live-search="true" >
                    @foreach($getAllRooms as $getAllRoom)
                        <option value="{{ $getAllRoom['id'] }}">{{ $getAllRoom['property_name'] }}</option>
                    @endforeach
              </select>
              <br>
              <br>

              <div class="datepicker-container-check">
                <input type="text" name="checkInDate" id="bookingDate" placeholder="Search Booking Date"  class="form-control">
              </div>
             <br> 
                  <input type="submit" class="btn btn-success" value="Search" />
             <br>
             <br>
            </form>

this line in here

<input type="text" name="checkInDate" id="bookingDate" placeholder="Search Booking Date"  class="form-control">

My controller

 $checkInDate = $request->get('checkInDate');
 $checkInDateExp = explode("to", $checkInDate);

 $checkDate = $checkInDateExp[0];
        $checkDateTo = $checkInDateExp[1];

Then my query display

 $getCheckDates  = BookingHistory::orWhereBetween('checkin_date', [$checkDate, $checkDateTo])->where('confirmed', 1)->get()->toArray();

            echo "<pre>";
            print_r($getCheckDates); exit;
            echo "</pre>";

I don't know why it returns an empty array this is the result when passing the data from my form

2019-11-15
2019-12-29

Array
(
)

Can someone help me figured this thing out?. Since the orWhereBetween works when the data is static. Now if the data is passed from the form no display. Any help is muchly appreciated. TIA

I hope this helps

 $getCheckDates  = BookingHistory::where('confirmed', 1)
              ->whereBetween('checkin_date', [$checkDate, $checkDateTo])
              ->get();
if($getCheckDates) {
  $getCheckDates = $getCheckDates->toArray(); # you may let it be object also
} else {
   // no any query result
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM