原始查询到Laravel查询

时间:2019-07-02 07:33:40

标签: mysql laravel

原始查询到Laravel查询

SELECT * FROM plans_subscriptions WHERE starts_on BETWEEN "2019-07-30" AND "2019-07-26" or expires_on BETWEEN "2019-07-20" AND "2019-07-22"

3 个答案:

答案 0 :(得分:0)

location ~ ^/image/(.*)$ {
    expires max;
    add_header Pragma public;
    add_header Cache-Control "public";

    root /;
    try_files /image_date/$1 /image_data_2/$1 =404;
}

答案 1 :(得分:0)

如果您想要对象响应,请使用此:

PlansSubscriptions::whereBetween('starts_on', ["2019-07-30", "2019-07-26"]);
                 ->orWhereBetween('expires_on', ["2019-07-20", "2019-07-22"]);
                 ->get();

如果要数组响应,请使用此命令:

PlansSubscriptions::whereBetween('starts_on', ["2019-07-30", "2019-07-26"]);
                 ->orWhereBetween('expires_on', ["2019-07-20", "2019-07-22"]);
                 ->get()->toArray();

我们可以这样设置日期格式:

$start = date("Y-m-d",strtotime($request->input('from_date')));
$end = date("Y-m-d",strtotime($request->input('to_date')));

并在查询中使用该变量,如下所示:

PlansSubscriptions::whereBetween('starts_on', [$start, $end]);
                 ->orWhereBetween('expires_on', ["2019-07-20", "2019-07-22"]);
                 ->get()->toArray();

答案 2 :(得分:0)

检查此

$users = DB::table('plans_subscriptions')
->where(function ($query){
  $query->whereBetween('starts_on', ['2019-07-30', '2019-07-26'])
        ->orWhereBetween('starts_on', ['2019-07-20', '2019-07-22']);
})
->get();