选择一个用户
where id =! Auth::user->id
// this prevents the query returning the current user logged in
where Auth::user->value1 ,'=', 'value1' || 'value2' || 'value3'
所以在英语中,找到一个用户名,其中 id 不等于当前登录的用户 ID,并且经过身份验证的用户的 value1 列等于另一个用户的 value1 或 value2 或 value 3column
下面是一个声明,我已经完成了它不能正常工作但是它在没有 OR 运算符的情况下工作
where(Auth::user()->recommendationWord1, '=' , 'value1')
此语句是格式的示例,包含我尝试过的内容。
$Query = DB::table('users')
->select('username')
->where('id', '!=', Auth::user()->id)
->whereIn(Auth::user()->recommendationWord1 , '=', 'value1', '||' , 'value2', '||' , 'value3'
->get();
下面是我的 HTML 页面的代码以及我如何发布它
@foreach ($Query as $selectedUser)
Code formatting<p> {{ $selectedUser->username}}</p>
@endforeach
最佳答案
where in structure is ->whereIn('attribute', ['val1', 'val2', ...])
在你的情况下
DB::table('users')
->select('username')
->where('id', '!=', Auth::user()->id)
->whereIn(Auth::user()->recommendationWord1 , ['value1', 'value2', 'value3'])
->get();
关于php - 如何在 Laravel 查询中使用 AND 运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54728468/