Answers for "laravel many to many get related posts by category"

0

laravel many to many get related posts by category

$post = Post::where('slug', '=', $slug)->first();

$related = Post::whereHas('tags', function ($q) use ($post) {
    return $q->whereIn('name', $post->tags->pluck('name')); 
})
->where('id', '!=', $post->id) // So you won't fetch same post
->get();
Posted by: Guest on July-30-2021

Code answers related to "laravel many to many get related posts by category"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language