Pass two where statement into query I'm trying to let Laravel get two columns out of the database, like this:
$bookings = Booking::where([
['dropOffDate', '=', '06/06/2019'],
['pickUpDate', '=', '06/06/2019']
])->orderBy('flightTime', 'asc')->toSql();
dd($bookings);
But this returns:
"select * from `booking` where (`dropOffDate` = ? and `pickUpDate` = ?) order by `flightTime` asc"
Can you please show an example of your expected output? Because what toSql() does is shows you the query that's being executed. You might want to use ->get() instead to get the results back.
So I was just using toSql() for debugging. But when I change it to get() I only get one booking, but I'm expect 4 bookings. (2x from dropOffDate and 2x from pickUpDate)
@hjortur17 well then you need the date to either be dropOfDate OR pickUpDate so this is the query that you need:
Booking::where('dropOffDate', '06/06/2019')
->orWhere('pickUpDate', '06/06/2019')
->orderBy('flightTime', 'asc')
->get();
(dropOffDate= ? andpickUpDate= ?) using AND there means BOTH conditions must be true. Using OR would mean EITHER can be true.
Okay but how can I render two separate divs? For example border green for dropOffDate and border red for pickUpDate?
@foreach ($bookings as $booking)
@if ($booking->dropOffDate)
<div class="border-t-8 border-green-400">
<h1>{{ $booking->carNumber }}</h1>
</div>
@elseif ($booking->pickUpDate)
<div class="border-t-8 border-red-400">
<h1>{{ $booking->carNumber }}</h1>
</div>
@endif
@endforeach
Each record has both values or is one always null?
Does what you showed not work?
No, I am expanding 2 red boxes and 1 green but I get 3 boxes all with green.
Please sign in or create an account to participate in this conversation.