Open Fajendagba opened 1 year ago
I need to be able to know if the current visitor has already viewed a post or not. I want this to be able to sort post orderBy post not yet viewed.
I also need to know if the current Auth user has already viewed a post, so that post can be sorted by post not yet viewed.
I've read many blogs and articles, but found none useful.
Hi @Fajendagba, are you able to get it? I need the same requirement.
No @iamB0rgy I haven't seen the solution. But in case you get it first, please drop it here. Thank you.
I am also searching for the same , any solutions?
@iamB0rgy @iamB0rgy the solution is actually simpler than I thought. Here it is
public function home(Request $request, Visitor $visitor)
{
$visitorId = $visitor->id();
// Get all post that hasn't been viewed by the visitor yet
// Make sure your Post model implements Viewable
$postsNotYetViewed = Post::whereIn('id', $posts->pluck('id'))
->whereDoesntHave('views', function ($query) use ($visitorId) {
$query->where('visitor', $visitorId);
})
->orderBy('created_at', 'desc')
->paginate($limit);
return view('post', [
'posts' => $posts,
]);
}
I need to be able to know if the current visitor has already viewed a post or not. I want this to be able to sort post orderBy post not yet viewed.
I also need to know if the current Auth user has already viewed a post, so that post can be sorted by post not yet viewed.
I've read many blogs and articles, but found none useful.