Get the post details if it has at least one comment in comments table
Get the post details if it has at least one comment in comments table
In this tutorial, we will try to find the solution to "Get the post details if it has at least one comment in comments table" through programming.
If you want to get the post details of a particular post which has at least one commet in comments table then you can use whereHas() method with callback function to get the post.-
Get the post details if it has at least one comment in comments table
$posts = Post::whereHas('comments', function($query){ $query->where('post_id', 1); })->get();
It will return the post details if there are comments regarding this particular post (post_id is 1 in comments table) exists in the comments table.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Generate unique username in Laravel
- Define variable and use in Laravel controller method
- How to get IP address in laravel
- SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
- How to get list of all views file in laravel
- How to access the nth object from Laravel collection object ?
- Laravel get single row by id
- Laravel file size validation not working
- Laravel create default admin user
- How to validate form input data in laravel
- Laravel 10 starter app using breeze on live server
- How to create new user without form submission in laravel
- How to call controller function from view in Laravel
- How to create controller in laravel
- How to make Copy or Duplicate table row in laravel
- If condition in foreach loop in laravel
- Create user in Laravel using tinker
- How to get route name on visit URL in laravel
- Symlink(): No such file or directory
- How to get specific columns using Laravel eloquent methods
- How to get specific columns using with method in laravel Eloquent relationship
- The use statement with non-compound name 'Auth' has no effect
- How to check data inserted or deleted in pivot after toggle method
- Submit form without CSRF token in Laravel
- How to get images from AWS s3 and display in Laravel blade