This is my model
public function getBookingDetails()
{
return $this->hasMany(BookingDetail::class,"booking_id","id");
}
Controller
public function showAllBookings(){
$bookings = Booking::with('getBookingDetails')->get();
return view('test_view_booking',compact('bookings'));
}
Blade
@foreach($bookings as $booking)
<td>{{ $booking->getBookingDetails->date_from->format('M d Y') }}</td>
td>{{ $booking->getBookingDetails->date_to->format('M d Y') }}</td>
It says
Property [date_from] does not exist on this collection instance.
It works with:
<td>{{ $booking->getBookingDetails[0]->date_from->format('M d Y') }}</td>
<td>{{ $booking->getBookingDetails[0]->date_to->format('M d Y') }}</td>
But only one data is shown.
This is my db: Booking
id|user_id|inventory_id
1|5|1
BookingDetails
id|booking_id|date_from|time_from|date_to|time_to
1|1|2019-03-18|15:30:00|2019-03-19|15:45:00
2|1|2019-04-18|15:30:00|2019-04-19|15:45:00