Overview

Namespaces

  • rsanchez
    • Deep
      • App
        • EE
        • Laravel
          • Facade
      • Collection
      • Hydrator
      • Model
      • Plugin
      • Relations
      • Repository

Classes

  • HasManyFromRepository
  • HasOneFromRepository
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: 
 3: /**
 4:  * Deep
 5:  *
 6:  * @package      rsanchez\Deep
 7:  * @author       Rob Sanchez <info@robsanchez.com>
 8:  */
 9: 
10: namespace rsanchez\Deep\Relations;
11: 
12: use Illuminate\Database\Eloquent\Relations\HasOne;
13: use Illuminate\Database\Eloquent\Builder;
14: use Illuminate\Database\Eloquent\Model;
15: use rsanchez\Deep\Repository\RepositoryInterface;
16: 
17: /**
18:  * Relation for fetching one related model from repositories instead of models
19:  */
20: class HasOneFromRepository extends HasOne
21: {
22:     /**
23:      * @var \rsanchez\Deep\Repository\RepositoryInterface
24:      */
25:     protected $repository;
26: 
27:     /**
28:      * The repository method used when filling out the relationship
29:      * @var string
30:      */
31:     protected $repositoryMethod;
32: 
33:     /**
34:      * {@inheritdoc}
35:      *
36:      * @param \Illuminate\Database\Eloquent\Builder         $query
37:      * @param \Illuminate\Database\Eloquent\Model           $parent
38:      * @param string                                        $foreignKey
39:      * @param string                                        $localKey
40:      * @param \rsanchez\Deep\Repository\RepositoryInterface $repository
41:      * @param string                                        $repositoryMethod
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:      * {@inheritdoc}
53:      */
54:     public function addConstraints()
55:     {
56:     }
57: 
58:     /**
59:      * {@inheritdoc}
60:      */
61:     public function addEagerConstraints(array $models)
62:     {
63:     }
64: 
65:     /**
66:      * {@inheritdoc}
67:      */
68:     public function getResults()
69:     {
70:         return call_user_func(array($this->repository, $this->repositoryMethod), $this->parent->getAttribute($this->localKey));
71:     }
72: }
73: 
API documentation generated by ApiGen 2.8.0