Laravel WhereHas then orWhereHas Example

Today, We want to share with you Laravel WhereHas then orWhereHas Example.In this post we will show you difference between where and wherehas in laravel 6, hear for orWhereHas on relation with whereHas in Laravel 6 we will give you demo and example for implement.In this post, we will learn about Laravel 6 wherehas laravel relation with an example.

Laravel WhereHas then orWhereHas Example

There are the Following The simple About Laravel6 WhereHas then orWhereHas Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel hasmanythrough pivot, so the some major files and Directory structures for this example is following below.

Laravel 6 whereHas with orWhereHas Examples

simple Laravel 6 whereHas with orWhereHas in Laravel controller define a method

public function myProducts()
    $products = Product::with(['pid', 'pname']);
    if ($request->has('name')) {
         $products = $products->whereHas('pid', function( $query ) use ( $request ){
                      $query->where('name', $request->name);
                  })->orWhereHas('pname', function( $query ) use ( $request ){
                      $query->where('name', $request->name);
    $products = $products->get();

simple loaded both associations first and then simple chained the whereHas and orWhereHas

$product = $product->with('homeCategory');
$product = $product->with('awayCategory');

    $product = $product->whereHas('homeCategory', function( $query ) use ( $parameterValues ){
      $query->where('pname', 'zommer' );
  })->orWhereHas('awayCategory', function( $query ) use ( $parameterValues ){
      $query->where('pname', 'zommer' );
Web Programming Tutorials Example with Demo

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about LaravelPHP WhereHas then orWhereHas Example.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment