
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
- Array to string conversion laravel blade
- If condition in foreach loop in laravel
- Get count of filter data, while return a small set of records
- Get last record from table in laravel
- External link not working in laravel blade
- How to pass external link in laravel blade to anchor tag
- How to update record after save method in Laravel
- Laravel hasmany select not working
- How to remove P tag from CkEditor in Laravel?
- Laravel route parameter
- Method Illuminate\Http\Request::validated does not exist
- Call to a member function pluck() on null
- Get ids in array from users table
- How to check if user has created any post or not in laravel
- Update if exist else insert new record in laravel
- How to check column value of a record is null or not in laravel
- Send id with route Laravel
- How to create belongstomany relation using custom name on custom pivot table
- Symlink(): No such file or directory
- How to validate URL with https using regex in laravel
- Remove array keys and values if it does not exist in other array in Laravel
- The POST method is not supported for this route. Supported methods: PUT.
- Get the post details if it has at least one comment in comments table
- How to get specific columns using with method in laravel Eloquent relationship
- Redirect from www to non www in laravel using htaccess