Created
October 30, 2020 19:15
-
-
Save jtelesforoantonio/01d3ec38fbd36ae6781fa61cb5b9d760 to your computer and use it in GitHub Desktop.
Disable the default model relationships for Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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