php - How to get data from foreach loop result

one text

Solution:

You should use arraypush function to get result.

 $attendance = DB::table('attendance')
             ->where('company_id', $request->company_id)
             ->where(DB::raw("in_out"),"=", "in")
             ->where(DB::raw("(STR_TO_DATE(attendance_time,'%Y-%m-%d'))"), "=", $date)->get();

$employee_checkin = [];
foreach($attendance as $atd){

                    // return $data[] = $atd->employee_id;
                  
                    $employee_in_company = DB::table('employee_in_company')
                    ->join('employee', 'employee.id', '=', 'employee_in_company.employee_id')
                    ->where('employee_in_company.company_id', $atd->company_id)
                    ->where(DB::raw("employee.id"),"!=", $atd->employee_id)
                    ->select('employee.name as name_company', 'employee_in_company.company_id', 
                             'employee_in_company.employee_id')
                    ->get();
                  
                    array_push($employee_checkin, $employee_in_company);
    
                }

                return $employee_checkin;

Source