Skip to content

Commit 8ed2189

Browse files
committed
Merge pull request #1 from nWidart/patch-1
Add trait to add the custom nested collection class
2 parents 628271d + 11ae0ef commit 8ed2189

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ protected $fillable = array(
1515
}
1616
```
1717

18-
and must have this method :
18+
and must use the following trait:
1919

2020
```php
21-
public function newCollection(array $models = array())
22-
{
23-
return new \TypiCMS\NestableCollection($models);
24-
}
21+
22+
use TypiCMS\NestableTrait;
23+
2524
```
2625

2726
Now each time you get a collection of that model, it will be an instance of **TypiCMS\NestableCollection** in place of **Illuminate\Database\Eloquent\Collection**.

src/NestableTrait.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php namespace TypiCMS;
2+
3+
trait NestableTrait
4+
{
5+
/**
6+
* Return a custom nested collection
7+
*
8+
* @param array $models
9+
* @return NestedCollection
10+
*/
11+
public function newCollection(array $models = array())
12+
{
13+
return new NestableCollection($models);
14+
}
15+
}

0 commit comments

Comments
 (0)