PHPackages                             resultsystems/relationships - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. resultsystems/relationships

ActiveLibrary[Database &amp; ORM](/categories/database)

resultsystems/relationships
===========================

Several Relations for Laravel.

0.5.1(5y ago)111.7k21MITPHPPHP &gt;=7.0.0

Since Jan 21Pushed 5y ago2 watchersCompare

[ Source](https://github.com/resultsystems/relationships)[ Packagist](https://packagist.org/packages/resultsystems/relationships)[ RSS](/packages/resultsystems-relationships/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (9)Used By (1)

Relationships
=============

[](#relationships)

This package adds two more kind of relationships based on Laravel's original from *Has Many Through*

- [Installation](#installation)
- [Has One Through Several](#has-one-through-several)
- [Has Many Through Several](#has-many-through-several)
- [How To Use](#how-to-use)

Installation
------------

[](#installation)

In the **require** key of **composer.json** file add the following:

```
"resultsystems/relationships": "~0.4.0"
```

**Important:** Do not use `dev-master`. Instead, use the tagged version, like shown before.

Run the Composer **update** comand:

```
composer update
```

or

```
composer require resultsystems/relationships
```

Has One Through Several
-----------------------

[](#has-one-through-several)

- Similar to Laravel's hasOne

The "has-one-through-several" relationship provides a convenient shortcut for accessing distant relations via an intermediate relation. For example, a `Frequency` model might have one `Subject` model through the intermediates `Skill` and `Schedule` model. In this example, you could easily gather subject for a given frequency. Let's look at the tables required to define this relationship:

```
frequencies
    id - integer
    schedule_id - integer
    date - date

skills
    id - integer
    teacher_id - integer
    subject_id - integer
    title - string

schedules
    id - integer
    group_id - integer
    skill_id - integer
    name - string

subjects
    id - integer
    name - string

    // model = frequency
    // frequency.schedule_id = schedules.id
    // schedules.skill_id = skills.id
    // skills.subject_id = subjects.id

```

```
