
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 upload files to amazon s3 bucket using Laravel
- SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'posts_user_id_foreign'; check that column/key exists
- Target class [HomeController] does not exist
- The use statement with non-compound name 'DB' has no effect
- How to restore multiple records after soft-deletes in Laravel
- Permanently delete a record in laravel
- Get count of filter data, while return a small set of records
- If condition in foreach loop in laravel
- How to get last year records count with month wise in Laravel
- Update email with unique validation in laravel
- How to check relationship is loaded or not in Laravel
- Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()
- Global scope in Laravel with example
- How to authenticate admin users in Laravel ?
- Laravel hasmany select not working
- Drop foreign key column in Laravel using migration
- Laravel create default admin user
- Insert data with form validation using ajax in laravel
- Update last created record in Laravel
- How to run a specific seeder class in laravel
- Class 'App\Http\Controllers\User' not found
- Pass value from controller to model in laravel
- Argument 1 passed to App\Http\Controllers\Auth\LoginController::authenticated() must be an instance of App\Http\Controllers\Auth\Request
- Eager loading dynamically in laravel
- Display message with session flash using bootstrap alert class in laravel