0

Heei, I want to show data according to daterange. Specifically data on this day and 6 days to go. Here's my code now.

Controller

$hari = [];

for ($i=0; $i < 6; $i++) 
{
   $hari[] = date("Y M d") + $i;
}

$booking_room = jadwal_meeting::whereBetween('tanggal', [$hari, $hari + 6])->get();
return view('homepage')->with($booking_room);

Note: 'tanggal' is a field on table.

But I just get error like this

Unsupported operand types : $booking_room = jadwal_meeting::whereBetween('tanggal', [$hari, $hari + 6])->get();

What's wrong with my code, anyone can help me please :)

3
  • Is $hari a string or a Carbon instance? Commented Apr 27, 2018 at 19:41
  • Please check my answer below. Commented Apr 28, 2018 at 12:31
  • @JonasStaudenmeir the result of $hari should be a string Commented Apr 30, 2018 at 3:05

2 Answers 2

1

Since $hari is an array, you have to use something like this:

$booking_room = jadwal_meeting::whereBetween('tanggal', [$hari[0], $hari[5]])->get();

Or more general:

$booking_room = jadwal_meeting::whereBetween('tanggal', [$hari[0], end($hari)])->get();
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, you save my time :)
1

Try this code it will help you.

$from = '2018-04-12'; 
$to = date('Y-m-d', strtotime($from. ' + 6 days'));

$reservations = Reservation::whereBetween('tanggal', [$from, $to])
->get();

Thanks,

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.