Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
znck committed Oct 23, 2015
1 parent 2bed694 commit 7e36525
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Within your eloquent model class add following line

```php
class User extends Model {
use \Znck\Eloquent\Relations\BelongsToThroughTrait;
use \Znck\Eloquent\Traits\BelongsToThrough;
...
}
```
Expand All @@ -28,7 +28,7 @@ Consider a blog application. In this app, a country can have many users and a us

```php
class Country extends Model {
use \Znck\Eloquent\Relations\BelongsToThroughTrait;
use \Znck\Eloquent\Traits\BelongsToThrough;

public function articles () {
return $this->hasManyThrough(Article::class, User::class);
Expand All @@ -40,7 +40,7 @@ If we are accessing the country of the article, then we have to use `$article->u

```php
Class Article extends Model {
use \Znck\Eloquent\Relations\BelongsToThroughTrait;
use \Znck\Eloquent\Traits\BelongsToThrough;

public function country() {
return $this->belongsToThrough(Country::class, User::class);
Expand All @@ -50,3 +50,44 @@ Class Article extends Model {

Now, the magic: `$article->country`

> And more deeper
```php

use Illuminate\Database\Eloquent\Model;
use Znck\Eloquent\Traits\BelongsToThrough;

class Country extends Model
{

}

class State extends Model
{

}

class District extends Model
{
use BelongsToThrough;

public function country()
{
return $this->belongsToThrough(Country::class, State::class);
}
}

class City extends Model
{
use BelongsToThrough;

public function country()
{
return $this->belongsToThrough(Country::class, [State::class, District::class]);
}
}

$city = City::find(1);

$city->country;
```

0 comments on commit 7e36525

Please sign in to comment.