Skip to content

Instantly share code, notes, and snippets.

@colindecarlo
Created November 18, 2017 16:37
Show Gist options
  • Save colindecarlo/29f12f1b3a4ed11aff92b270838c8856 to your computer and use it in GitHub Desktop.
Save colindecarlo/29f12f1b3a4ed11aff92b270838c8856 to your computer and use it in GitHub Desktop.
<?php
class Event
{
public function fights()
{
return $this->hasMany(Fight::class)->orderBy('fightcard_order');
}
public function topFight()
{
return $this->hasOne(Fight::class)->orderBy('fightcard_order');
}
}
// what's the difference
$topFight = $event->topFight()->with(['fighter1', 'fighter2'])->get();
// between
$topFight = $event->topFight->load(['fighter1', 'fighter2']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment