Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

marc_ronaldo's avatar

How can i do to run 3 queries as one

I've been try to merge three queries but have had a hard time doing so.here is the code.

public function precise_transact(Request $request){

    $month = $request->month;
    $year = $request->year;
    $date = $request->date;
    $date_query = Transaction::whereRaw("day(created_at)=?",[$date]);
    $year_query = Transaction::whereRaw("year(created_at)=?",[$year]);
    $transactions = Transaction::whereRaw("month(created_at)=?",[$month])
    ->union($date_query)
    ->union($year_query)
    ->get();

}

0 likes
3 replies
Sinnbeck's avatar

Maybe you could tell what is going wrong?

1 like
marc_ronaldo's avatar

thanks and sorry for the late reply, i already found the solution to my problem

Please or to participate in this conversation.