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

Sabbir345's avatar

Multiple table eloquent

I want data from three table using where clause but employee and attendance table working but vacation table data not working. Please help

Here is my controller :

   $first     =  $request->employee_id_first;
    $second    =  $request->employee_id_last;
    $dateYear  =  date('Y', strtotime($request->datepicker));
    $dateMonth =  date('m', strtotime($request->datepicker));

$data = Employee::with(['attendance' => function ($query) use ($dateYear,$dateMonth) { $query->whereYear('datetime', $dateYear) ->whereMonth('datetime', $dateMonth); },'vacation' => function ($query) use ($dateYear,$dateMonth){ $query->whereYear('datetime', $dateYear) ->whereMonth('datetime', $dateMonth); }])->get();

0 likes
1 reply
Cronix's avatar

Try using 2 separate ->with() statements. One for attendance, and another for vacation. It's hard to tell with it unformatted and jumbled all together, but that looks like it might be it.

2 likes

Please or to participate in this conversation.