9
votes

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?

1

1 Answers

16
votes

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!