]> BookStack Code Mirror - bookstack/blobdiff - app/Actions/View.php
Added examples, updated docs for image gallery api endpoints
[bookstack] / app / Actions / View.php
index de30900c76f2a6d4600a75f726dd9645fe7713ff..706467133fa5ecc36ec6aaeaecd9e48f88595f48 100644 (file)
@@ -1,7 +1,11 @@
-<?php namespace BookStack\Actions;
+<?php
 
+namespace BookStack\Actions;
+
+use BookStack\Auth\Permissions\JointPermission;
 use BookStack\Interfaces\Viewable;
 use BookStack\Model;
+use Illuminate\Database\Eloquent\Relations\HasMany;
 use Illuminate\Database\Eloquent\Relations\MorphTo;
 
 /**
@@ -16,7 +20,6 @@ use Illuminate\Database\Eloquent\Relations\MorphTo;
  */
 class View extends Model
 {
-
     protected $fillable = ['user_id', 'views'];
 
     /**
@@ -27,6 +30,12 @@ class View extends Model
         return $this->morphTo();
     }
 
+    public function jointPermissions(): HasMany
+    {
+        return $this->hasMany(JointPermission::class, 'entity_id', 'viewable_id')
+            ->whereColumn('views.viewable_type', '=', 'joint_permissions.entity_type');
+    }
+
     /**
      * Increment the current user's view count for the given viewable model.
      */