To filter only videos or series that you have not yet watched on Laracasts, you typically need to use the platform's built-in filtering features. However, if you're building a similar feature in your own Laravel application, you might have a videos table and a video_user pivot table that tracks which users have watched which videos.
Here's an example solution in Laravel:
Assuming you have the following relationships:
Userhas manywatchedVideos(many-to-many withVideo)Videomodel
You can filter unwatched videos for the authenticated user like this:
$unwatchedVideos = Video::whereDoesntHave('watchedByUsers', function ($query) {
$query->where('user_id', auth()->id());
})->get();
If you want to filter unwatched series, assuming a Series model and a relationship between series and videos:
$unwatchedSeries = Series::whereHas('videos', function ($query) {
$query->whereDoesntHave('watchedByUsers', function ($q) {
$q->where('user_id', auth()->id());
});
})->get();
Explanation:
whereDoesntHavechecks for videos that do not have a record in the pivot table for the current user.- Adjust the relationship names (
watchedByUsers,videos) as per your actual model definitions.
If you are referring to the actual Laracasts website, use the "Not Watched" filter available in the sidebar under the "Browse" section. This will show you all videos and series you haven't watched yet.