+ $query = $this->morphMany(Comment::class, 'entity');
+ return $orderByCreated ? $query->orderBy('created_at', 'asc') : $query;
+ }
+
+ /**
+ * Get the related search terms.
+ * @return \Illuminate\Database\Eloquent\Relations\MorphMany
+ */
+ public function searchTerms()
+ {
+ return $this->morphMany(SearchTerm::class, 'entity');
+ }
+
+ /**
+ * Get this entities restrictions.
+ */
+ public function permissions()
+ {
+ return $this->morphMany(EntityPermission::class, 'restrictable');
+ }
+
+ /**
+ * Check if this entity has a specific restriction set against it.
+ * @param $role_id
+ * @param $action
+ * @return bool
+ */
+ public function hasRestriction($role_id, $action)
+ {
+ return $this->permissions()->where('role_id', '=', $role_id)
+ ->where('action', '=', $action)->count() > 0;
+ }
+
+ /**
+ * Get the entity jointPermissions this is connected to.
+ * @return \Illuminate\Database\Eloquent\Relations\MorphMany
+ */
+ public function jointPermissions()
+ {
+ return $this->morphMany(JointPermission::class, 'entity');