Skip to content

Instantly share code, notes, and snippets.

@ricardoaugusto
Last active April 9, 2020 14:07
Show Gist options
  • Save ricardoaugusto/f799e51db4531d91771e03c12ac71761 to your computer and use it in GitHub Desktop.
Save ricardoaugusto/f799e51db4531d91771e03c12ac71761 to your computer and use it in GitHub Desktop.
Laravel HasManyThrough explanation
class Current extends Model
{
public function final()
{
return $this->hasManyThrough(
'App\Final',
'App\Intermediate',
'intermediate_id', // Foreign key on Intermediate
'final_id', // Foreign key on Final
'id', // Local key on Current
'id' // Local key on Intermediate
);
}
}
@ricardoaugusto
Copy link
Author

Because I'm always forgetting those keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment