【问题标题】:How to change laravel orm to my query如何将 laravel orm 更改为我的查询
【发布时间】:2023-03-24 01:43:01
【问题描述】:

我在 laravel orm 中的查询后发生了变化。但这行不通。

在 sql 中

select * from `promotions` join items on items.id = promotions.item_id where promotions.start >= "2014-12-30" and promotions.end <="2015-01-30"

按顺序

$result = Promotion::whereNull('promotions.deleted_at')
                ->select('promotions.*','items.name as i_name')
                ->join('items', 'items.id', '=', 'promotions.item_id')
                ->where('start', '>=', $start || 'end', '<=', $end)
                ->get();

【问题讨论】:

    标签: php mysql laravel orm


    【解决方案1】:

    链两个where调用:

    ->where('start', '>=', $start)
    ->where('end', '<=', $end)
    

    或使用whereBetween

    【讨论】:

    • 我两个都用。首先不行。但是第二个 whereBetween 还可以,但是我有 2 个参数 start 和 end
    • @nainglinhtut 那么请acceptJosephs 回答。谢谢
    猜你喜欢
    • 1970-01-01
    • 2019-05-02
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 2015-08-02
    • 2020-12-29
    • 2018-06-20
    • 1970-01-01
    相关资源
    最近更新 更多