How to get all posts which contains comments in laravel
How to get all posts which contains comments in laravel
In this session, we’ll try our hand at solving the "How to get all posts which contains comments in laravel" puzzle by using the computer language.
Sometimes you have to get all the posts which contains comments in laravel. You have to use the whereHas() method with relationship name to get all the records which have records that exist in the relationship (child) table using foreign key relation.-
Get all posts which contains comments in laravel
$posts = Post::whereHas('comments')->get(); dd($posts);
This code snippet will return all the posts which has at least one comment exists in 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
- Laravel route redirect not working
- How to insert value to additional columns in pivot table in laravel
- Wheredate in laravel not working
- How to check column value of a record is null or not in laravel
- Laravel URL validation not working
- Get id of last inserted record in laravel
- How to pass query string to url in laravel
- Update if exist else insert new record in laravel
- Get comma separated email from input array
- How to create laravel project using composer
- Order by multiple columns in Laravel
- Get laravel version
- How to upload files to amazon s3 bucket using Laravel
- Get last year created records in Laravel
- Laravel get all records with pagination
- How to Access Array in blade laravel
- Target class [HomeController] does not exist
- Get count of filter data, while return a small set of records
- 419 page expired error in Laravel
- Call to a member function pluck() on null
- How to run a specific seeder class in laravel
- Get previous date data in laravel
- Docker important commands to run laravel application with docker
- Property [user] does not exist on this collection instance
- Get today records in Laravel