Skip to content

Commit cf1e6c9

Browse files
authored
cache navigable results
1 parent e81d059 commit cf1e6c9

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/Providers/EloquentProvider.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ abstract class EloquentProvider extends Provider
1515
* Eloquent model.
1616
*/
1717
protected $model;
18+
19+
/**
20+
* Cached items.
21+
*
22+
* @var Collection
23+
*/
24+
protected static $items;
1825

1926
/**
2027
* Provides a collection of Navigable elements.
@@ -23,11 +30,15 @@ abstract class EloquentProvider extends Provider
2330
*/
2431
protected function navigable()
2532
{
26-
return $this->repository()
27-
->get()
28-
->map(function ($item) {
29-
return new Eloquent($item);
30-
}, []);
33+
if (null === static::$items) {
34+
static::$items = $this->repository()
35+
->get()
36+
->map(function ($item) {
37+
return new Eloquent($item);
38+
}, []);
39+
}
40+
41+
return static::$items;
3142
}
3243

3344
/**

0 commit comments

Comments
 (0)