Skip to content

Instantly share code, notes, and snippets.

@sebastiaanluca
Created August 18, 2018 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastiaanluca/67036fc7809190072e0a72765cc9e2e8 to your computer and use it in GitHub Desktop.
Save sebastiaanluca/67036fc7809190072e0a72765cc9e2e8 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types=1);
namespace App\Models;
use SebastiaanLuca\BooleanDates\BooleanDates;
abstract class User extends Model
{
// Have to rename each getAttribute/setAttribute method
use BooleanDates, HasPublicDates {
BooleanDates::getAttribute as getBooleanDateAttribute;
HasPublicDates::getAttribute as getPublicDateAttribute;
}
/**
* Get an attribute from the model.
*
* @param string $key
*
* @return mixed
*/
public function getAttribute($key)
{
if (! $key) {
return null;
}
// Have to call each method in a specific order manually
// for each class that uses attribute methods
if ($this->hasBooleanDate($key)) {
return $this->getBooleanDate($key);
}
if ($this->hasPublicDate($key)) {
return $this->getPublicDate($key);
}
return parent::getAttribute($key);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment