Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] Update HasManyThrough Documentation #3306

Merged
merged 1 commit into from
May 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions eloquent-relationships.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,18 +368,20 @@ Now that we have examined the table structure for the relationship, let's define

The first argument passed to the `hasManyThrough` method is the name of the final model we wish to access, while the second argument is the name of the intermediate model.

Typical Eloquent foreign key conventions will be used when performing the relationship's queries. If you would like to customize the keys of the relationship, you may pass them as the third and fourth arguments to the `hasManyThrough` method. The third argument is the name of the foreign key on the intermediate model, the fourth argument is the name of the foreign key on the final model, and the fifth argument is the local key:
Typical Eloquent foreign key conventions will be used when performing the relationship's queries. If you would like to customize the keys of the relationship, you may pass them as the third and fourth arguments to the `hasManyThrough` method. The third argument is the name of the foreign key on the intermediate model, the fourth argument is the name of the foreign key on the final model, and the fifth argument is the local key. Lastly, the sixth argument is the second local key; the local key on the intermediate model:

class Country extends Model
{
public function posts()
{
return $this->hasManyThrough(
'App\Post', 'App\User',
'country_id', 'user_id', 'id'
'App\Post', 'App\User', 'country_id',
'user_id', 'id', 'id'
);
}
}

The local key (fifth argument), is matched up with the foreign key on the intermediate model (third argument). In the above example, the local key refers to the key on the `Country` model (calling class). The third argument, `country_id`, is an attribute on our intermediate model, `App\User`, so the condition is `countries.id = users.country_id`. The fourth and sixth arguments are then matched up to make the connection between the intermediate and final model. The fourth argument specifies the foreign key on the final model (`posts.user_id`), and the sixth argument specifies the local key on the intermediate model (`users.id`).

<a name="polymorphic-relations"></a>
### Polymorphic Relations
Expand Down