laravel按月统计用户出勤

时间:2018-07-13 05:33:10

标签: laravel

@foreach($users as $user)
{{$user->name }}
@foreach($user->attendances as $attend)
@if( $attend->date->format('F') === $today->format('F')  )
{{ $user->attendances->count() }}
@endif 
@endforeach
@endforeach 

答案=>总计数不是月份

1 个答案:

答案 0 :(得分:0)

这是简单的解决方案,雄辩的有whereDate和whereMonth方法,

{{ $user->attendances()->whereMonth('created_at',\Carbon\Carbon::now()->format('m') )->count() }} 

希望会有所帮助