Laravel WhereHas then orWhereHas Example

Laravel php Programming Technology

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.

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

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.

Related FAQ

Here are some more FAQ related to this Article:

  1.   PHP Array Remove specific value Example
  2.   Simple Eloquent Laravel One to One Relationship
  3.   Woocommerce Featured Image URL and Gallery images in Wordpress
  4.   Laravel 5.7 Google reCAPTCHA Tutorial with Example
  5.   One to Many Relationship in Laravel 5.7 Eloquent
  6.   Laravel Pivot Tables Tutorial Example
  7.   Laravel JOIN Multiple Tables Eloquent Relationships
  8.   Real time progress bar With PHP
  9.   JQuery Allow Only Numbers Input in Textbox
  10.   Polymorphic One to Many Relationship Example

Leave a Reply

Your email address will not be published. Required fields are marked *