I am building a venue manangement system, and on the landing page, i m trying to show all the available slots to the visitors. The ones that have already been booked are shown as not available. I have created two variables, one that carries the info from the time table and the other from the booking table and tyring to use blade to compare and show. This is how I am trying to implement it in blade:
@foreach($times as $time)
@foreach($bookings as $booking)
<tr>
@if($time->availble_times == $booking->booking_time)
<td>{{$time->availble_times}}: not available</td>
@else
<tr><td>{{$time->availble_times}}</td>
@endif
</tr>
@endforeach
@endforeach
But what this does instead is show all the times for as many records in the bookings table. Like if there are two rows in the bookings table, it shows the times twice, and so on. Just in case, here is my controller function:
public function times(){
$times = Times::all();
$bookings = Bookings::all();
return view('/test2')->with('times', $times)->with('bookings', $bookings);
}
I recently started doing Laravel and cannot figure out this issue. My question is, how can i fix the n-times display issue and show the user which times are booked and which are available?
@foreach($times as $time)
will not show all the times if with every iteration you print something – Bartłomiej Sobieszek Jun 11 '17 at 19:32$model->search(...)
– Bartłomiej Sobieszek Jun 11 '17 at 20:05