Created
October 30, 2020 19:15
-
-
Save jtelesforoantonio/e058b9b8ca874613f8c88ff160c12556 to your computer and use it in GitHub Desktop.
Disable default model appends 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 WithoutAppends | |
{ | |
/** | |
* Determines if the defaults appends fields will be present. | |
* | |
* @var bool | |
*/ | |
public static bool $withoutAppends = false; | |
/** | |
* Appends only the following fields. | |
* | |
* @var array | |
*/ | |
public static array $onlyThisFields = []; | |
protected function getArrayableAppends() | |
{ | |
if (self::$withoutAppends) { | |
return self::$onlyThisFields; | |
} | |
return parent::getArrayableAppends(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment