/** * Get all of the models from the database. Overrides the base behavior to * add the category slug as a condition. * * @param array $columns * An array of columns to access. * * @return \Illuminate\Database\Eloquent\Collection|static[] */ public static function all($columns = ['*']) { // If there's a defined taxonomy slug, attach that. $instance = new static(); if (isset($instance->taxonomy_slug) && $instance->taxonomy_slug) { // Return a constrained collection. $columns = is_array($columns) ? $columns : func_get_args(); return $instance->newQuery()->where('taxonomy', $instance->taxonomy_slug)->get($columns); } // Return the parent's behavior, if nothing is set. return parent::all($columns); }
/** * Default constructor. Overrides BaseModel::__construct(). * * @return void */ public function __construct() { parent::__construct(); $this->attributes['taxonomy'] = $this->taxonomy_slug; }
/** * Overloads the default __get() magic method. Used to return a possible * meta key value. * * @param string $name * A meta_key name. * * @return mixed */ public function __get($name) { // Check to see if the meta key exists. if ($meta = $this->meta()->where('meta_key', $name)->first()) { // Use WP's default maybe_unserialize function to handle possible // serialized data. return maybe_unserialize($meta->meta_value); } // No, the key doesn't exist, so return the parent's action. return parent::__get($name); }