childs [id, name, DOB]
bookings [id, child_id, club, day]
Child.php
public function bookings(){ return $this->hasMany('Booking', 'bookings'); }
Booking.php
public function child(){ return $this->belongsTo('Child', 'child_id');
$child = Child::find(1);
$bookings = $child->bookings;
foreach($bookings as $booking) echo $booking->child->name;
Is this along the right lines?
Editing on these forums blows. Sorry for the above formatting issue but the line
Should be the only thing in `Booking.php` for my example
Thanks, thats pretty much what I had i was just calling it wrong, for some reason i thought more work would be involved to reverse it but simply this $booking->child->name; does the job... gotta love Laravel
Thanks man
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community