Mam pytanie czy w laravelu jest gdzies dostepna metoda typu case albo when tak jak w przypadku metod .where()/.orWhere() bo chcę użyć w instrukcji warunkowej WHERE instrukcji WHEN tak jak się używa when w zapytaniu SELECT tylko jak chce użyć w klauzuli .where() i wpisuję do google case when laravel method ale nic nie ma jak próbowałem użyć wywołania funkcji .case() to był komunikat nie ma takiej funkcji i stąd moje pytanie czy są gotowe funkcje w laravelu do tych czynności ?
Mój kod za to odpowiedzialny:
return self::selectRaw("moods.id as id")
->selectRaw("moods.date_start as date_start")
->selectRaw("moods.date_end as date_end")
->selectRaw("moods.level_mood as level_mood")
->selectRaw("moods.level_anxiety as level_anxiety")
->selectRaw("moods.level_nervousness as level_nervousness")
->selectRaw("moods.level_stimulation as level_stimulation")
->selectRaw("moods.epizodes_psychotik as epizodes_psychotik")
->selectRaw("moods.type as type")
->selectRaw("((unix_timestamp(date_end) - unix_timestamp(date_start)) * level_mood) as average_mood")
->selectRaw("((unix_timestamp(date_end) - unix_timestamp(date_start)) * level_anxiety) as average_anxiety")
->selectRaw("((unix_timestamp(date_end) - unix_timestamp(date_start)) * level_nervousness) as average_nervousness")
->selectRaw("((unix_timestamp(date_end) - unix_timestamp(date_start)) * level_stimulation) as average_stimulation")
->selectRaw("moods.what_work as what_work ")
->where("moods.id_users",$IdUsers)
->case(function ($query) use ($date,$startDay) {
$query->when('moods.type',"mood")->then(
$query2->whereRaw(DB::Raw("(DATE(IF(HOUR( moods.date_start) >= '" . $startDay . "', moods.date_start,Date_add(moods.date_start, INTERVAL - 1 DAY) )) ) = '" . $date . "'" ))
->orWhereRaw(DB::Raw("(DATE(IF(HOUR( moods.date_end) >= '" . $startDay . "', moods.date_end,Date_add(moods.date_end, INTERVAL - 1 DAY) )) ) = '" . $date . "'" ))
)
->else($query3->whereRaw(DB::Raw("(DATE(IF(HOUR( moods.date_start) >= '" . 0 . "', moods.date_start,Date_add(moods.date_start, INTERVAL - 1 DAY) )) ) = '" . $date . "'" ))
->orWhereRaw(DB::Raw("(DATE(IF(HOUR( moods.date_end) >= '" . 0 . "', moods.date_end,Date_add(moods.date_end, INTERVAL - 1 DAY) )) ) = '" . $date . "'" )));
})
->orderBy("moods.date_start")
->get();