You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For users with role editor, I want to be able to show all the posts so no filter is required.
For user with role of viewer, I want to hide the private posts, unless they are explicitly allowed to peek at the post or they are the creator of the post.
So for this I have implemented something like this,
// If the user is of level viewer i.e. role_id > 3if ($user->role_id > 3) {
// allow to view public visibility$posts= $posts->where('visibility', '=', 'public');
//allow to view if peeking is granted$posts = $posts->orWhereHas('peek', function ($query) use ($user, $params) {
$query->where('user_id', $user->id);
});
//allow to view if creator$posts = $posts->orWhereHas('creator', function ($query) use ($user, $params) {
$query->where('user_id', $user->id);
});
The issue is that when we try to filter the posts by title it still gets all the posts where the user has peeking rights. So how can the filter be applied to this?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a situation where I am allowing filters based on IDs like:
For users with role
editor
, I want to be able to show all the posts so no filter is required.For user with role of
viewer
, I want to hide the private posts, unless they are explicitly allowed to peek at the post or they are the creator of the post.So for this I have implemented something like this,
The issue is that when we try to filter the posts by
title
it still gets all the posts where the user has peeking rights. So how can the filter be applied to this?Beta Was this translation helpful? Give feedback.
All reactions