【问题标题】:Method Illuminate\Database\Eloquent\Collection::orWhere does not exist方法 Illuminate\Database\Eloquent\Collection::orWhere 不存在
【发布时间】:2019-05-24 06:15:47
【问题描述】:

我遇到了问题 方法Illuminate\Database\Eloquent\Collection::orWhere 不存在。我只是想在那个案例上使用 orWhere

我尝试在最后一个查询中添加->get(),但仍然出错

$category = Auth::user()->division->allCode->where('parent', '0')->where('info_code', 'code_h')
            ->orWhere('info_code','=', 'code_m')->where('parent', '0');

我想在这种情况下使用 or where 并得到结果。这是我想要的逻辑

(parent==0 && info_code == code_h) || (parent==0 && info_code == code_m)

【问题讨论】:

    标签: laravel laravel-5 eloquent


    【解决方案1】:

    毕竟使用() 代码如:Auth::user()->division->allCode()->where...

    【讨论】:

    • 我不明白。你能教我吗?我有这个问题 $notifications = Auth::user()->notifications ->where('type', 'App\Notifications\UserUpdate')->orWhere('type', 'App\Notifications\PostUpdate')->采取(10); "Method Illuminate\\Notifications\\DatabaseNotificationCollection::orWhere does not exist."
    • 调用方法将提供 hasMany 类,您可以继续修改您的查询。如果调用与关系方法同名的prop;它就像 notifications()->get() 将返回模型集合而不是查询构建器。因为模型集合也有 where 方法,就像 builder 一样,所以在 orWhere 调用时会出现错误。
    猜你喜欢
    • 2020-11-21
    • 2021-09-08
    • 2020-11-13
    • 2019-12-11
    • 2020-02-04
    • 2019-11-12
    • 2019-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多