
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
- Display data in table using foreach in Laravel
- Global scope in Laravel with example
- Laravel append URI in route
- Composer create project laravel/laravel example app
- How to get route name on visit URL in laravel
- How to check column value of a record is null or not in laravel
- How to automatically update the timestamp of parent model in Laravel
- Method Illuminate\Http\Request::validated does not exist
- InRandomOrder() method with example in laravel
- Laravel get all records with pagination
- How to validate form input data in laravel
- Get today records in Laravel
- How to insert dynamic values to additional column with pivot column in pivot table on multiple records
- Validation errors for multiple forms on same page Laravel
- Get products with number of orders in Laravel
- Get current month records in laravel 7/8
- Update existing pivot table data in laravel
- How to display user profile after login in laravel
- Laravel specific table Migration
- How to upload image in laravel 8
- Redirect to another view from controller in laravel
- How to use or operator in laravel
- Route [password.request] not defined
- Call to undefined relationship [user] on model [App\Models\Post]
- Call to a member function pluck() on null