Laravel-5.6'LIKE'在哪里选择 [英] Laravel-5.6 'LIKE' in where select

查看:97
本文介绍了Laravel-5.6'LIKE'在哪里选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此查询,但出现错误:

I use this query and i get a error :

 $description = $request->get('description');
        if (!empty($description)){
        $description_query = Transcationhistorique::where(['sender_id' => $user_id, "%$description%", 'LIKE','description'])
            ->orWhere('receiver_id', $user_id)->get();
        }else{
            $description_query  =  "" ;
        }

这是我得到的错误:

"SQLSTATE [42S22]:找不到列:1054'where中的未知列'0' 子句"(SQL:从transcation_historique中选择*,其中 (sender_id = 32和0 =%salaire%,并且1 = LIKE和2 = 说明)或receiver_id = 32)"

"SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from transcation_historique where (sender_id = 32 and 0 = %salaire% and 1 = LIKE and 2 = description) or receiver_id = 32)"

这就是我真正想要运行的:

and this what really i want to run:

select * from `transcation_historique` where (`sender_id` = 32 and `description` = %salaire%) or `receiver_id` = 32)

推荐答案

尝试一下,

$description_query = Transcationhistorique::where(
                         function($query) use ($user_id, $description){
                             return $query->where('sender_id', $user_id)
                                          ->where('description', 'like', '%' . $description .'%');

                         }
                     )
                     ->orWhere('receiver_id', $user_id)
                     ->get();

这篇关于Laravel-5.6'LIKE'在哪里选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆