Воспроизвести в красноречивом - PullRequest
0 голосов
/ 25 февраля 2019

Я не могу воспроизвести этот запрос в красноречивом.

Как я мог сделать запрос без красноречивого?

select * from points where operator = 2 and (month(date) = '1' and day(date) >= 25 or month(date) = '2' and day(date) <= 24)

Ответы [ 2 ]

0 голосов
/ 25 февраля 2019

Для этой цели вы можете использовать фасад DB.

$query = "select * from points where operator = :operator and (month(date) = :monthDate and day(date) >= :dayDate or month(date) = :monthDate2 and day(date) <= :dayDate2)"

$points = DB::select($query,[
   "operator" => 2,
   "monthDate" => 1,
   "dayDate" => 25,
   "monthDate2" => 2,
   "dayDate2" => 24
])
0 голосов
/ 25 февраля 2019

Учитывая, что у вас есть Point модель для таблицы points, ниже должен работать красноречивый запрос:

<?php

$points  = Point::where('operator', 2)->where(function($q){
    return $q->whereMonth('date', '=', 1)->whereDay('date', '>=', 25);
})->orWhere(function($q){
    return $q->whereMonth('date', '=', 2)->whereDay('date', '<=', 24);
})->get();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...