my code from folder in App\Reports\ExportReport.php
class ReportExport implements FromCollection
{
$cross_kehadiran[] = DB::table('attendance as in')
->where('in.in_out', 'in')
->where('in.attendance_location_id', $locations->id)
->where('in.company_id', '!=', \Session::get('selected_company'))
->whereDate('in.created', Carbon::today())
->leftJoin('attendance as out', function ($join) {
$join->on('in.employee_id', 'out.employee_id')
->where('out.in_out', 'out')
->where('out.attendance_location_id', 'in.attendance_location_id')
->whereDate('out.created', Carbon::today());
})
->join('employee', 'employee.id', 'in.employee_id')
->join('location_library', 'location_library.id', 'in.attendance_location_id')
->join('company as cp', 'cp.id', 'in.company_id')
->join('employee_in_app as e_app', 'e_app.employee_id', 'in.employee_id')
->select('employee.name', 'cp.alias', 'in.employee_id','location_library.location_name', DB::raw('DATE_FORMAT(in.attendance_time, "%H:%i:%s") as in_time'), DB::raw('DATE_FORMAT(out.attendance_time, "%H:%i:%s") as out_time'), 'e_app.note')
->orderBy('in.attendance_time', 'DESC')
->get();
return $cross_kehadiran;
}
I made export excel in laravel, when i return using dd($cross_kehadiran) the data i want appears but when i use return $cross_kehadiran i get error : Call to a member function all() on array in. How to solve my problem, help me, thanks.
CodePudding user response:
import this class at the tope use Maatwebsite\Excel\Concerns\FromCollection;
Put all of your code in the collection method according to Maatwebsite\Excel package.
public function collection()
{
return DB::table('attendance as in')
->where('in.in_out', 'in')
->where('in.attendance_location_id', $locations->id)
->where('in.company_id', '!=', \Session::get('selected_company'))
->whereDate('in.created', Carbon::today())
->leftJoin('attendance as out', function ($join) {
$join->on('in.employee_id', 'out.employee_id')
->where('out.in_out', 'out')
->where('out.attendance_location_id', 'in.attendance_location_id')
->whereDate('out.created', Carbon::today());
})
->join('employee', 'employee.id', 'in.employee_id')
->join('location_library', 'location_library.id', 'in.attendance_location_id')
->join('company as cp', 'cp.id', 'in.company_id')
->join('employee_in_app as e_app', 'e_app.employee_id', 'in.employee_id')
->select('employee.name', 'cp.alias', 'in.employee_id','location_library.location_name', DB::raw('DATE_FORMAT(in.attendance_time, "%H:%i:%s") as in_time'), DB::raw('DATE_FORMAT(out.attendance_time, "%H:%i:%s") as out_time'), 'e_app.note')
->orderBy('in.attendance_time', 'DESC')
->get();
}
CodePudding user response:
you should return like this
return collect($cross_kehadiran);