for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace LaravelFreelancerNL\Aranguent\Eloquent\Relations;
use Illuminate\Database\Eloquent\Relations\MorphTo as IlluminateMorphTo;
class MorphTo extends IlluminateMorphTo
{
/**
* Set the base constraints on the relation query.
*
* @return void
*/
public function addConstraints()
if (static::$constraints) {
$this->query->where($this->ownerKey, '==', $this->child->{$this->foreignKey});
}
* Get all of the relation results for a type.
* @param string $type
* @return \Illuminate\Database\Eloquent\Collection
protected function getResultsByType($type)
$instance = $this->createModelByType($type);
$ownerKey = $this->ownerKey ?? $instance->getKeyName();
$query = $this->replayMacros($instance->newQuery())
->mergeConstraintsFrom($this->getQuery())
->with(array_merge(
$this->getQuery()->getEagerLoads(),
(array) ($this->morphableEagerLoads[get_class($instance)] ?? [])
))
->withCount(
(array) ($this->morphableEagerLoadCounts[get_class($instance)] ?? [])
);
$whereIn = $this->whereInMethod($instance, $ownerKey);
return $query->{$whereIn}(
$ownerKey,
$this->gatherKeysByType($type)
)->get();