
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 pass data to partial view file in laravel
- Create records using relationship in laravel
- SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'user_id'
- How to create pivot table in laravel using migration
- How to create project_user pivot table in laravel
- Ignore Records where a field has NULL value in Laravel
- Root composer.json requires php ^7.3 but your php version (8.0.0) does not satisfy that requirement
- How to create laravel project using composer
- Display success message in laravel
- Create user in Laravel using tinker
- Laravel route redirect not working
- Laravel 9 pagination with search filter
- Get today records in Laravel
- Laravel get single row by id
- The openssl extension is required for SSL/TLS protection but is not available
- How to create and run user seeder in laravel
- How to pass data to route in laravel?
- Get duplicate records in laravel
- Print last executed query in laravel
- Get last week data in Laravel
- Update email with unique validation in laravel
- Redirect from www to non www in laravel using htaccess
- Trying to get property 'title' of non-object
- 419 page expired error in Laravel
- Remove array keys and values if it does not exist in other array in Laravel