php - 如何在 Laravel 查询中使用 AND 运算符?

标签 php mysql laravel

选择一个用户

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/

相关文章:

php - 警告 : getimagesize() [function. getimagesize] : Filename cannot be empty warning message?

php - 在php中将3个表合并到一个选择查询中

如果内容与现有内容相似,c++ mysql_query update将返回错误(但无法与正常错误区分开来)

mysql - 如何使用 SQL 查询获取该表单的数据

Laravel 5.2 - bootstrap/cache/services.php 丢失

php - Laravel - 使用复选框将数据发送到数据透视表

javascript - 在 CodeIgniter 中使用 Bootstrap 提交 jQuery 表单

php - Doctrine 存储库 "Doctrine\ORM\EntityRepository"必须实现 Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface

mysql - 创建一个使用来自两个表的条​​件的查询?

php - 无法在 Laravel 项目中使用 Visual Code 进行调试