mirror of
https://github.com/danog/psalm-plugin-laravel.git
synced 2024-12-02 09:37:47 +01:00
107 lines
2.5 KiB
Plaintext
107 lines
2.5 KiB
Plaintext
<?php
|
|
|
|
namespace Illuminate\Database\Eloquent\Relations;
|
|
|
|
use Closure;
|
|
use Illuminate\Support\Arr;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Traits\Macroable;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Query\Expression;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
use Illuminate\Support\Traits\ForwardsCalls;
|
|
|
|
/**
|
|
* @template TRelatedModel
|
|
* @mixin \Illuminate\Database\Eloquent\Builder<TRelatedModel>
|
|
*/
|
|
abstract class Relation
|
|
{
|
|
use ForwardsCalls, Macroable {
|
|
__call as macroCall;
|
|
}
|
|
|
|
/**
|
|
* The Eloquent query builder instance.
|
|
*
|
|
* @var \Illuminate\Database\Eloquent\Builder
|
|
* @psalm-var \Illuminate\Database\Eloquent\Builder<TRelatedModel>
|
|
*/
|
|
protected $query;
|
|
|
|
/**
|
|
* The parent model instance.
|
|
*
|
|
* @var \Illuminate\Database\Eloquent\Model
|
|
*/
|
|
protected $parent;
|
|
|
|
/**
|
|
* The related model instance.
|
|
*
|
|
* @var \Illuminate\Database\Eloquent\Model
|
|
* @psalm-var TRelatedModel
|
|
*/
|
|
protected $related;
|
|
|
|
/**
|
|
* Create a new relation instance.
|
|
*
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
* @param \Illuminate\Database\Eloquent\Model $parent
|
|
* @return void
|
|
*/
|
|
public function __construct(Builder $query, Model $parent)
|
|
{
|
|
$this->query = $query;
|
|
$this->parent = $parent;
|
|
$this->related = $query->getModel();
|
|
|
|
$this->addConstraints();
|
|
}
|
|
|
|
/**
|
|
* Get the relationship for eager loading.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Collection
|
|
* @psalm-return \Illuminate\Database\Eloquent\Collection<TRelatedModel>
|
|
*/
|
|
public function getEager()
|
|
{
|
|
return $this->get();
|
|
}
|
|
|
|
/**
|
|
* Execute the query as a "select" statement.
|
|
*
|
|
* @param array $columns
|
|
* @return \Illuminate\Database\Eloquent\Collection
|
|
* @psalm-return \Illuminate\Database\Eloquent\Collection<TRelatedModel>
|
|
*/
|
|
public function get($columns = ['*'])
|
|
{
|
|
return $this->query->get($columns);
|
|
}
|
|
|
|
/**
|
|
* Get the underlying query for the relation.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Builder<TRelatedModel>
|
|
*/
|
|
public function getQuery()
|
|
{
|
|
return $this->query;
|
|
}
|
|
|
|
/**
|
|
* Get the related model of the relation.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Model
|
|
* @psalm-return TRelatedModel
|
|
*/
|
|
public function getRelated()
|
|
{
|
|
return $this->related;
|
|
}
|
|
}
|