Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

why orWhere Operator not working in laravel

In my code i want to search by product_name and merchant_name but when i use orWhere operator i get this error

BadMethodCallException: Method Illuminate\Database\Eloquent\Collection::orWhere does not exist. in file /Users/admin/Desktop/GSM Source Code/API/vendor/laravel/framework/src/Illuminate/Macroable/Traits/Macroable.php on line 113

 public function search($name)
{

    $brand = Brand::join('product_categories','product_categories.id','=','brands.category')
    ->join('products','products.id','=','brands.product')
    ->join('merchants','merchants.id','=','brands.merchant')
    ->join('new_shops','new_shops.id','=','brands.shop')
    ->get([
        'brands.id',
        'brands.image',
        'product_categories.category',
        'products.product_name',
        'merchants.merchant_name',
        'new_shops.shop_name',
        'brands.activation',
        'brands.created_at',
        'brands.updated_at'
    ])->where('product_name',$name)
    ->orWhere('merchant_name',$name);

    return new BrandResource($brand);

}

Also when i use LIKE operator in the where clause it doesnot not give any result

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you must use where and orWhere after get, like this:

$brand = Brand::join('product_categories','product_categories.id','=','brands.category')
    ->join('products','products.id','=','brands.product')
    ->join('merchants','merchants.id','=','brands.merchant')
    ->join('new_shops','new_shops.id','=','brands.shop')
     ->where('product_name',$name)
    ->orWhere('merchant_name',$name)
    ->get();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading