Laravel ORM怎么用where case end?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Laravel ORM怎么用where case end?相关的知识,希望对你有一定的参考价值。

SELECT
c.`id`, c.`nickname`, cp.`id`
FROM
grshop.grs_customer AS c
LEFT JOIN
grs_customer_partner AS cp ON cp.`customer_id` = c.`recommend_customer_id`
WHERE
1 = CASE
WHEN c.`recommend_customer_id` = 0 THEN 0
WHEN
c.`recommend_customer_id` != 0
AND cp.`id` > 0
AND cp.`type` = 0
AND cp.`status` = 1
AND c.`created_at` > cp.`updated_at`
THEN
1
ELSE 2
END
GROUP BY c.`id`
ORDER BY c.`id` DESC;

参考技术A $query->whereRaw('LENGTH(code)=12');

laravel ORM 模型关联 with () 用法

关联时想对关联表数据筛选时:
MySQL查询:

SELECT *  FROM A
LEFT JOIN B
ON A.B_id = B.id AND B.condition = $condition

ORM模型查询使用with():

Model::with([‘table_name‘ => function ($query) use ($condition) {
            $query->where( "condition", $condition)
                        }])->get();)

 

轉載:https://laravel-china.org/articles/7171/laravel-learning-records-orm-with-usage-model-association


以上是关于Laravel ORM怎么用where case end?的主要内容,如果未能解决你的问题,请参考以下文章

laravel orm where 条件中 mysql函数 怎么用

Laravel ORM 怎么在条件语句中做本表的一个字段和关联表的字段做比较?

laravel 的 Eloquent ORM 查询前50条数据 怎么查

laravel ORM怎么打印出执行sql语句

Laravel Eloquent ORM 中的 join()->where()

sql中where后面用case的问题