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

Laravel 9 ConsoleTvs Charts Tutorial Example


consoletvs/charts laravel 9 ,consoletvs charts laravel 9 ,laravel 9 chart consoletvs ,consoletvs/charts laravel 9 tutorial ,laravel charts,laravel ch...

Integrate Summernote Tutorial Example in Laravel 9


laravel summernote editor example, how to use summernote editor in laravel, how to install summernote in laravel, summernote editor in laravel, larave...

Laravel – Where Condition with Two Columns Example


laravel where with two column example, two column where laravel , table column condition in laravel , laravel where column equals column example

Laravel where and orWhere Condition Example


how to use where and orwhere condition in laravel 8, laravel 8 where and orwhere condition, where and orwhere laravel 8 example, orwhere and where in...

How to Install Ckeditor in Laravel 9


Laravel 9 ckeditor tutorial example, you will learn how to install or integrate ckeditor and use in laravel 9 app