1: <?php
2:
3: 4: 5: 6: 7: 8:
9:
10: namespace rsanchez\Deep\Relations;
11:
12: use Illuminate\Database\Eloquent\Relations\HasMany;
13: use Illuminate\Database\Eloquent\Builder;
14: use Illuminate\Database\Eloquent\Model;
15: use rsanchez\Deep\Repository\RepositoryInterface;
16:
17: 18: 19:
20: class HasManyFromRepository extends HasMany
21: {
22: 23: 24:
25: protected $repository;
26:
27: 28: 29: 30:
31: protected $repositoryMethod;
32:
33: 34: 35: 36: 37: 38: 39: 40: 41: 42:
43: public function __construct(Builder $query, Model $parent, $foreignKey, $localKey, RepositoryInterface $repository, $repositoryMethod = 'find')
44: {
45: parent::__construct($query, $parent, $foreignKey, $localKey);
46:
47: $this->repository = $repository;
48: $this->repositoryMethod = $repositoryMethod;
49: }
50:
51: 52: 53:
54: public function addConstraints()
55: {
56: }
57:
58: 59: 60:
61: public function addEagerConstraints(array $models)
62: {
63: }
64:
65: 66: 67:
68: public function getResults()
69: {
70: return call_user_func(array($this->repository, $this->repositoryMethod), $this->parent->getAttribute($this->localKey));
71: }
72: }
73: