Я использую Laravel 5.4.Мне написан запрос с красноречивым Laravel.Он работает правильно, когда я вручную пишу запрос на сервер MySQL, но Tt не работает, когда я кодирую тот же запрос Laravel Eloquent.
Пожалуйста, помогите ...
Код Laravel
$dateS = new Carbon($req->fromDate);
$dateE = new Carbon($req->toDate);
$tasks = DB::table('taskday')->selectRaw("taskday.dayID, taskday.task_date, taskday.fk_userID, userdetails.fullname, count(assignedtask.fk_dayID) as total")
->join("assignedtask","assignedtask.fk_dayID","taskday.dayID")
->join("userdetails","userdetails.userID","taskday.fk_userID")
->whereBetween("taskday.task_date", [$dateS->format('Y-m-d')." 00:00:00", $dateE->format('Y-m-d')." 23:59:59"]);
if($req->staffname > 0){
$tasks = $tasks->where('taskday.fk_userID',$req->staffname);
}
$tasks = $tasks->groupBy("assignedtask.fk_dayID")->get();
return $tasks;
Мой SQL-запрос
select `taskday`.`dayID`, `taskday`.`task_date`, `taskday`.`fk_userID`, `userdetails`.`fullname`, count(`assignedtask`.`fk_dayID`) as total
from `taskday` inner join `assignedtask` on `assignedtask`.`fk_dayID` = `taskday`.`dayID`
inner join `userdetails` on `userdetails`.`userID` = `taskday`.`fk_userID`
where `taskday`.`task_date` between '2018-11-01 00:00:00' and '2018-12-19 23:59:59'
group by `assignedtask`.`fk_dayID`
После прямого запроса на mysql он дает правильный результат
dayID task_date fk_userID fullname total
-------- ---------- ---------- ---------- -------------
DAY021 2018-12-02 USR300920 Manish 2
DAY022 2018-12-03 USR300924 Rovio 3
Laravel выдает ошибку
(2/2) QueryException
SQLSTATE[42000]: Syntax error or access violation: 1055 'medical.taskday.dayID'
isn't in GROUP BY
(SQL: select taskday.dayID, taskday.task_date, taskday.fk_userID, userdetails.fullname, count(assignedtask.fk_dayID) as total
from `taskday` inner join `assignedtask` on `assignedtask`.`fk_dayID` = `taskday`.`dayID`
inner join `userdetails` on `userdetails`.`userID` = `taskday`.`fk_userID`
where `taskday`.`task_date`
between 2018-11-01 00:00:00 and 2018-12-19 23:59:59
group by `assignedtask`.`fk_dayID`)
Пожалуйста, помогите