Mam taki problem tworzę zaawansowane wyszukiwanie i teraz jak w opcji wyszukiwania zaznaczę dawka dobowa czyli to wykona instrukcje warunkową
$usee->groupBy("dat");
To dostaje komunikat
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'dat' in 'group statement' (SQL: select count(*) as aggregate from `usees` left join `products` on `products`.`id` = `usees`.`id_products` left join `forwarding_descriptions` on `usees`.`id` = `forwarding_descriptions`.`id_usees` left join `descriptions` on `descriptions`.`id` = `forwarding_descriptions`.`id_descriptions` where `usees`.`id_users` = 38 and `products`.`id` in (160) group by `dat`)
Tak jak by w ogóle nie wykonywał tych wszystkich selectRawów, ale z kolei jak nie będzie tej opcji dawka dobowa to działa wszystko dobrze i tylko nie działa dla paginate dla get działa i dla simplepaginate też działa co jest nie tak daje cource code.
public function createQuestions($bool) {
$usee = usee::query();
$hour = $this->selectHourStart(Auth::User()->id);
$usee
->selectRaw("products.name as name")
->select( DB::Raw("(DATE(IF(HOUR(usees.date) >= $hour, usees.date,Date_add(usees.date, INTERVAL - 1 DAY) )) ) AS dat "))
->selectRaw("hour(usees.date) as hour")
->selectRaw("sum(usees.portion) as por")
->selectRaw("day(usees.date) as day")
->selectRaw("month(usees.date) as month")
->selectRaw("year(usees.date) as year")
->selectRaw("usees.portion as portion")
->selectRaw("usees.date as date")
->selectRaw("descriptions.description as description")
->selectRaw("descriptions.date as date_description")
->selectRaw("usees.id_products as product")
->leftjoin("products","products.id","usees.id_products")
->leftjoin("forwarding_descriptions","usees.id","forwarding_descriptions.id_usees")
->leftjoin("descriptions","descriptions.id","forwarding_descriptions.id_descriptions")
->where("usees.id_users",Auth::User()->id);
if (Input::get("data1") != "") {
$usee->where("usees.date",">=",Input::get("data1"));
}
if (Input::get("data2") != "") {
$usee->where("usees.date","<=",Input::get("data2"));
}
if (Input::get("dose1") != "" and Input::get("day") == "") {
$usee->where("usees.portion",">=",Input::get("dose1"));
}
if (Input::get("dose2") != "" and Input::get("day") == "") {
$usee->where("usees.portion","<=",Input::get("dose2"));
}
if (Input::get("search") != "") {
$usee->where("descriptions.description","like","%" . Input::get("search") . "%");
}
if (Input::get("inDay") != "") {
$usee->where("descriptions.description","!=", "");
}
if ($bool == true) {
$usee->whereIn("products.id",$this->id_product);
}
//chodzi o to
if (Input::get("day") != "") {
$usee->groupBy("dat");
if (Input::get("dose1") != "" ) {
$usee->havingRaw("sum(usees.portion) >= " . Input::get("dose1"));
}
if (Input::get("dose2") != "" ) {
$usee->havingRaw("sum(usees.portion) <= " . Input::get("dose2"));
}
}
else {
$usee->groupBy("usees.id");
}
$list = $usee->orderBy(Input::get("sort"),"DESC")->paginate(200);
//foreach ($list as $l) {
// print $l->name;
//}
return $list;
}
$bool == true
?