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.

Read Also:  Laravel 6 Eloquent Has With and WhereHas

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

Read Also:  How To Print Last Query In PHP?

$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.

Read Also:  Laravel 5.7 Get Current Page URL path

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  PHP Barcode Generator Tutorial with Example
  2. Read Also:  Polymorphic One to Many Relationship Example
  3. Read Also:  Bootstrap Toggle Inside JQuery DataTable
  4. Read Also:  Simple Eloquent Laravel One to One Relationship
  5. Read Also:  Check if value exists jQuery in Array – jQuery.inArray()
  6. Read Also:  Nested Queries Subqueries in SQL Example
  7. Read Also:  Laravel Eloquent with Collection Contains
  8. Read Also:  Laravel Eloquent Get Last Inserted Id
  9. Read Also:  Laravel JOIN Multiple Tables Eloquent Relationships
  10. Read Also:  How to Create html to pdf using php | Convert HTML to PDF using PHP