Method or Where does not exist. Laravel 5.3

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

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

If I try without using "orWhere", if I use it, it gives an error. Does anyone know where the error is?

+4
source share
1 answer

You are trying to use orWherein collections, which is why it shows you an error. You should use this on such a model (assuming Categoryas 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!

+8
source

Source: https://habr.com/ru/post/1662658/


All Articles