We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 204930d commit 8c98864Copy full SHA for 8c98864
1 file changed
src/Models/Post.php
@@ -375,6 +375,29 @@ public function reject(): void
375
: $this->getDraftKey();
376
}
377
378
+
379
+ /**
380
+ * Determine posts that a user can see
381
+ *
382
+ * @param $query
383
+ * @param PostType $type
384
+ * @return mixed
385
+ */
386
+ public function scopeUserVisibleForPostType($query, PostType $type)
387
+ {
388
+ $admin = auth()->user();
389
390
+ if ($admin) {
391
+ if ($admin->can('create', $type) && $admin->can('editOthers', $type)) {
392
+ // Admin can edit all posts
393
+ return $query;
394
+ }
395
396
397
+ // everyone can view published
398
+ return $query->published();
399
400
401
/**
402
* Get the content blocks
403
* Default to one single raw block
0 commit comments