In this exercise, I will explain Laravel whereHas and orWhereHas query model, wherehas and orWhereHas query utilized in Laravel for relationships.
In this way, here I will give you a model of how to utilize wherehas in Laravel, wherehas expressive in Laravel 8 work same as has() work.
has() is to channel the choosing model dependent on a relationship. So it acts likewise to a typical WHERE condition. In the event that you basically use has(?relation?) that suggests you just need to get the models that have no lesser amount of related model in this connection.
whereHas() works essentially equivalent to has() yet permits you to determine extra channels for the connected model to check.

whereHas() Example - 1

$blogs = Blogs::whereHas('comments', function (Builder $query) {
                          $query->where('content', 'like', 'code%');
                })->get();

whereHas() Example - 2

$users = User::whereHas('posts', function($q){
                $q->where('created_at', '>=', '2022-01-01 00:00:00');
         })->get();

I hope you will like the content and it will help you to learn Laravel whereHas and orWhereHas Query Example
If you like this content, do share.


Recommended Posts

View All

How to install Adminer in Laravel application


In this article we will install Adminer in Laravel 8 application

Laravel 8 Stripe Subscription Tutorial Using Cashier Example


laravel cashier, stripe laravel, laravel subscription tutorial, laravel 8 cashier tutorial, laravel 8 stripe subscription tutorial

Most Important Array Methods in JavaScript


Learn the most important array methods in JavaScript, including push, pop, shift, unshift, forEach, map, filter, reduce, and find. Improve your coding...

Convert PDF to Image Tutorial Example in Laravel 9


Example of Laravel pdf to picture. You will discover how to use the Laravel 8 app to convert PDF to picture in this tutorial.

Laravel One to One Eloquent Relationship Tutorial


Laravel One To One Eloquent Relationships Tutorial Example, Laravel Eloquent ORM is the best possible database solution, ORM Mapping is very easy, lar...