Skip to content

Instantly share code, notes, and snippets.

@jtelesforoantonio
Created October 30, 2020 19:15
Show Gist options
  • Save jtelesforoantonio/e058b9b8ca874613f8c88ff160c12556 to your computer and use it in GitHub Desktop.
Save jtelesforoantonio/e058b9b8ca874613f8c88ff160c12556 to your computer and use it in GitHub Desktop.
Disable default model appends for Laravel
<?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