Skip to content

Instantly share code, notes, and snippets.

@jtelesforoantonio
Created October 30, 2020 19:15
Show Gist options
  • Save jtelesforoantonio/01d3ec38fbd36ae6781fa61cb5b9d760 to your computer and use it in GitHub Desktop.
Save jtelesforoantonio/01d3ec38fbd36ae6781fa61cb5b9d760 to your computer and use it in GitHub Desktop.
Disable the default model relationships for Laravel
<?php
namespace App\Traits\Model;
trait WithoutRelationships
{
/**
* Determines if the defaults relationships will be present.
*
* @var bool
*/
public static bool $withoutRelations = false;
public function newQueryWithoutScopes()
{
return $this->newModelQuery()
->with(self::$withoutRelations ? [] : $this->with)
->withCount($this->withCount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment