]> BookStack Code Mirror - bookstack/blobdiff - app/Entity.php
Continued with database work for permissions overhaul
[bookstack] / app / Entity.php
index 4f97c6bab255caa63e880a19c187469942666a9c..35badb4611ddd5f8e727461e21a81747301d5a1a 100644 (file)
@@ -73,6 +73,15 @@ abstract class Entity extends Ownable
         return $this->restrictions->where('role_id', $role_id)->where('action', $action)->count() > 0;
     }
 
+    /**
+     * Get the entity permissions this is connected to.
+     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
+     */
+    public function permissions()
+    {
+        return $this->morphMany(EntityPermission::class, 'entity');
+    }
+
     /**
      * Allows checking of the exact class, Used to check entity type.
      * Cleaner method for is_a.
@@ -81,7 +90,16 @@ abstract class Entity extends Ownable
      */
     public static function isA($type)
     {
-        return static::getClassName() === strtolower($type);
+        return static::getType() === strtolower($type);
+    }
+
+    /**
+     * Get entity type.
+     * @return mixed
+     */
+    public static function getType()
+    {
+        return strtolower(static::getClassName());
     }
 
     /**