我使用此查询,但出现错误:
$description = $request->get('description');
$description_query = Transcationhistorique::where(function ($query) use ($description, $user_id) {
$query->where('receiver_id', $user_id,'description', 'LIKE','%' . $description . '%')
->orWhere('description', 'LIKE','%' . $description . '%','sender_id', $user_id);
})->get();
这是我得到的错误:
“ SQLSTATE [42S22]:找不到列:1054'where中的未知列'0' 子句”(SQL:从
transcation_historique
中选择*,其中 (sender_id
= 32,0
=%salaire%,1
=相似,2
= 说明)或receiver_id
= 32)“
这就是我真正想要运行的:
select * from `transcation_historique` where (`sender_id` = 32 and `description` = %salaire%) or (`receiver_id` = 32 and `description` = %salaire%)
答案 0 :(得分:5)
尝试
Transcationhistorique::where(function ($query) use ($description, $user_id) {
$query->where(['receiver_id' => $user_id, 'description' => 'LIKE %' . $description . '%'])
->orWhere(['description' => 'LIKE %' . $description . '%', 'sender_id' => $user_id]);
})->get();
答案 1 :(得分:1)
然后,您应使用以下语句:
$query = Transcationhistorique::where(function ($query) use ($description, $user_id) {
$query->where('receiver_id', $user_id)
->where('description', 'LIKE','%' . $description . '%');
})
->orWhere(function ($query) use ($description, $user_id) {
$query->where('sender_id', $user_id)
->where('description', 'LIKE','%' . $description . '%');
})
->get();
答案 2 :(得分:0)
您应该尝试以下操作:
$description = $request->get('description');
$query = Transcationhistorique::where(function ($query) use ($description, $user_id) {
$query->where('receiver_id', $user_id)
->where('description', 'LIKE','%' . $description . '%');
})
->orWhere(function ($query) use ($description, $user_id) {
$query->where('sender_id', $user_id)
->where('description', 'LIKE','%' . $description . '%');
})
->get();
答案 3 :(得分:0)
或尝试使用Query Builder:
$description_query = DB::table('transcationhistoriques')
->where(['receiver_id' => $user_id, 'description' => 'LIKE %' . $description . '%'])
->orWhere(['description' => 'LIKE %' . $description . '%', 'sender_id' => $user_id])
->get();