@mstrauss
still getting error
this is my EmpAttendance model
public function employee()
{
return $this->belongsTo('App\Employee', 'emp_id');
}
this is my Employee model
public function empattendance()
{
return $this->hasMany('App\EmpAttendance', 'emp_id');
}
and this is my code
$employees = Employee::withCount([
'empattendance',
'empattendance as present' => function (Builder $query) {
$query->where('att_count', 1);
}
])->get();
dd($employees);
i got this error
Type error: Argument 1 passed to App\Http\Controllers\EmpAttendanceController::App\Http\Controllers\{closure}() must be an instance of App\Http\Controllers\Builder, instance of Illuminate\Database\Eloquent\Builder given, called in C:\xampp\htdocs\Laravel\hotel_sri_ram_prasad\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php on line 934
and one important thing i dont have multiple columns for attendance count
att_date emp_id att-count reason
01/07 1 1
01/07 2 0 Leave fever
02/07 1 0.5 halfday fever
02/07 2 1
03/07 1 0 absent
so in the above for employee 1
the present days is 1.5 (1+0.5)
the absentdays is 1.5 (1+0.5) (here the problem is the 0 are absent so that must be count and 0.5 is half day that must be sum and then both must be added ). so the count of 0 is 1 and the sum of 0.5 is 0.5 so adding both 1.5 is the absent days
total days are 3 (1 + 1 + 1)