Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method orWhere does not exist. Laravel 5.3

BadMethodCallException in Macroable.php line 74: Method orWhere does not exist.

    $category = $categories->where('Node_ID', (explode('.', $cat{$title_id})[0]))
        ->orWhere('Node_Path', $cat->{$category_name})
        ->first();

If I try without "orWhere" works, if I use it, throws an Error. Someone knows where is the mistake?

like image 403
Adrián Silvestre Avatar asked Dec 02 '16 15:12

Adrián Silvestre


1 Answers

You are trying to use orWhere on collections, thats why its showing you the error. You should use this on model like this (taking Category as a Model):

$category = Category::where('Node_ID', (explode('.', $cat{$title_id})[0]))
                     ->orWhere('Node_Path', $cat->{$category_name})
                     ->first();

See Laravel Docs for orWhere()

Hope this helps!

like image 166
Saumya Rastogi Avatar answered Oct 19 '22 05:10

Saumya Rastogi