调用未定义的方法Illuminate \ Database \ Query \ Builder :: except()

时间:2017-03-26 00:41:48

标签: php laravel-5.4

我希望获得许多用户,不包括已登录的用户。但是在运行查询时出现此错误,我错过了什么?

  

调用未定义的方法Illuminate \ Database \ Query \ Builder :: except()

    $user = Auth::user()->id;
    $tests = $this->user->where('referrer', $user)
                  ->except($user)
                  ->orderBy('id')
                  ->take(2)
                   ->get();


    // $this->user was already injected in the constructor

1 个答案:

答案 0 :(得分:2)

尝试使用whereNotIn代替except(),因为我认为except()不是查询构建器的方法,或者已被弃用。

$user = Auth::user()->id;

$tests = $this->user->where('referrer', $user)
              ->whereNotIn('id', [$user])
              ->orderBy('id')
              ->take(2)
               ->get();

https://laravel.com/docs/5.4/queries#where-clauses