Method orWhere does not exist. Laravel 5.3

Deadly 提交于 2021-02-08 13:16:17

问题


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:


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!



来源:https://stackoverflow.com/questions/40935435/method-orwhere-does-not-exist-laravel-5-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!