for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Mblarsen\LaravelRepository\Traits;
trait IncludesRelations
{
/** @var array $allowed_with */
protected $allowed_with = [];
/** @var array $default_with */
protected $default_with = [];
public function setAllowedWith(array $allowed)
$this->allowed_with = $allowed;
return $this;
}
public function setDefaultWith(array $with)
$this->default_with = $with;
private function applyWith($query)
$requested_with = $this->resource_context->with();
if ($this->allowed_with === ['*']) {
$with = $requested_with;
} else {
$with = array_intersect($this->allowed_with, $requested_with);
$with = array_unique(array_merge($with, $this->default_with));
if (!empty($with)) {
$query->with($with);