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
- How to get all route list
- Drop foreign key column in Laravel using migration
- Method Illuminate\Http\Request::validated does not exist
- How to add dynamic page title in Laravel view
- Call to a member function update() on null
- How to get selected categories on edit record with Select2
- How to Get records between two dates in Laravel
- Class 'Facade\Ignition\IgnitionServiceProvider' not found
- How to add script on specific view file in laravel while extending layout
- Conditional validation in laravel
- How to set column as primary key in Laravel model
- Laravel 9 pagination with search filter
- External link not working in laravel blade
- Trying to access array offset on value of type null error in laravel
- Laravel recursive function in controller
- How to get specific columns using with method in laravel Eloquent relationship
- How to get id of next record in laravel
- The use statement with non-compound name 'DB' has no effect
- How to show data by ID in laravel?
- How to pass external link in laravel blade to anchor tag
- How to decrypt laravel password
- Pass variable from blade to controller Laravel
- Cast Array to an Object in Controller and then pass to view in laravel
- Call to a member function getRelationExistenceQuery() on array in Laravel
- Input file with max size validation in laravel