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.

Also Read This πŸ‘‰   PHP woocommerce_after_shop_loop_item Examples

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();
  
    dd($products);
}

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 :

Also Read This πŸ‘‰   Polymorphic One to Many Relationship Example

Summary

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

Free Live Chat for Any Issue

I hope you get an idea about LaravelPHP WhereHas then orWhereHas Example.
I would like to have feedback on my infinityknow.com 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.