1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-31 15:24:31 +03:00

Started base work on attribute system

This commit is contained in:
Dan Brown
2016-05-06 20:33:08 +01:00
parent 1903422113
commit 5080b4996e
7 changed files with 165 additions and 7 deletions

View File

@ -54,6 +54,15 @@ abstract class Entity extends Ownable
return $this->morphMany(View::class, 'viewable');
}
/**
* Get the Attribute models that have been user assigned to this entity.
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function attributes()
{
return $this->morphMany(Attribute::class, 'entity');
}
/**
* Get this entities restrictions.
*/
@ -114,6 +123,22 @@ abstract class Entity extends Ownable
return strtolower(static::getClassName());
}
/**
* Get an instance of an entity of the given type.
* @param $type
* @return Entity
*/
public static function getEntityInstance($type)
{
$types = ['Page', 'Book', 'Chapter'];
$className = str_replace([' ', '-', '_'], '', ucwords($type));
if (!in_array($className, $types)) {
return null;
}
return app('BookStack\\' . $className);
}
/**
* Gets a limited-length version of the entities name.
* @param int $length