class Parent extends Model
{
public function kids()
{
return $this->belongsToMany('App\Models\Kid')
->orderBy('age')
->withTimestamps();
}
public function oldestKid()
{
return $this->belongsToMany('App\Models\Kid')
->orderByDesc('age')
->take(1);
}
}
Problem with this approach is that $parent->oldestKid returns an array. It would feel more logical if it would return an object.
$parent = App\Models\Parent::with('oldestKid')->first();