Guys iam working with a school project. i have tow attendance module. staff and student attendance.
but staff attendance is easy, so i worked with that but everthing is in my report how to show it thats the problem.
this how my attendance are store in db staff_attendance table
Refer: https://imgur.com/Zvjwkch
id staff_id att-date att_count reason
1 1 10-10-19 1
2 2 10-10-19 0
3 1 11-10-19 0.5
4 2 11-10-19 1
here 1=present 0= absent 0.5 = halfday. the data area stored in row wise in table. for staff id 1 and 2 i have entered an attendance for two dates 10 and 11 october. here the records are in row wise
now what i expect in the report blade is
StaffName 10-10-19 11-10-19 . . . .
1 1 0.5
2 0 1
.
.
.
.
.
here iam expecting the report in column wise
so i made a query like this with the help of @mstrauss .
$attendances=StaffAttendance:: whereMonth('att_date' ,Carbon::parse($request->att_month)->month)->where('acc_year_id',$request->acc_year_id)->get()->groupBy('att_date');
and when i dd( $attendances)
Collection {#2036 ▼
#items: array:6 [▼
"2019-10-24" => Collection {#2030 ▶}
"2019-10-25" => Collection {#2031 ▶}
"2019-10-26" => Collection {#2032 ▶}
"2019-10-27" => Collection {#2033 ▶}
"2019-10-28" => Collection {#2034 ▶}
"2019-10-29" => Collection {#2035 ▶}
]
}
when i extend each date then
Collection {#2036 ▼
#items: array:6 [▼
"2019-10-24" => Collection {#2030 ▼
#items: array:18 [▶]
}
"2019-10-25" => Collection {#2031 ▶}
"2019-10-26" => Collection {#2032 ▶}
"2019-10-27" => Collection {#2033 ▶}
"2019-10-28" => Collection {#2034 ▶}
"2019-10-29" => Collection {#2035 ▶}
]
}
when i extend the array 18 means
Collection {#2036 ▼
#items: array:6 [▼
"2019-10-24" => Collection {#2030 ▼
#items: array:18 [▼
0 => StaffAttendance {#1919 ▶}
1 => StaffAttendance {#1920 ▶}
2 => StaffAttendance {#1921 ▶}
3 => StaffAttendance {#1922 ▶}
4 => StaffAttendance {#1923 ▶}
5 => StaffAttendance {#1924 ▶}
6 => StaffAttendance {#1925 ▶}
7 => StaffAttendance {#1926 ▶}
8 => StaffAttendance {#1927 ▶}
9 => StaffAttendance {#1928 ▶}
10 => StaffAttendance {#1929 ▶}
11 => StaffAttendance {#1930 ▶}
12 => StaffAttendance {#1931 ▶}
13 => StaffAttendance {#1932 ▶}
14 => StaffAttendance {#1933 ▶}
15 => StaffAttendance {#1934 ▶}
16 => StaffAttendance {#1935 ▶}
17 => StaffAttendance {#1936 ▶}
]
}
"2019-10-25" => Collection {#2031 ▶}
"2019-10-26" => Collection {#2032 ▶}
"2019-10-27" => Collection {#2033 ▶}
"2019-10-28" => Collection {#2034 ▶}
"2019-10-29" => Collection {#2035 ▶}
]
}
when i extend the staffAttendance array means
Collection {#2036 ▼
#items: array:6 [▼
"2019-10-24" => Collection {#2030 ▼
#items: array:18 [▼
0 => StaffAttendance {#1919 ▼
#fillable: array:5 [ …5]
#connection: "mysql"
#table: "staff_attendances"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:8 [ …8]
#original: array:8 [ …8]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [ …1]
}
1 => StaffAttendance {#1920 ▶}
2 => StaffAttendance {#1921 ▶}
3 => StaffAttendance {#1922 ▶}
4 => StaffAttendance {#1923 ▶}
5 => StaffAttendance {#1924 ▶}
6 => StaffAttendance {#1925 ▶}
7 => StaffAttendance {#1926 ▶}
8 => StaffAttendance {#1927 ▶}
9 => StaffAttendance {#1928 ▶}
10 => StaffAttendance {#1929 ▶}
11 => StaffAttendance {#1930 ▶}
12 => StaffAttendance {#1931 ▶}
13 => StaffAttendance {#1932 ▶}
14 => StaffAttendance {#1933 ▶}
15 => StaffAttendance {#1934 ▶}
16 => StaffAttendance {#1935 ▶}
17 => StaffAttendance {#1936 ▶}
]
}
"2019-10-25" => Collection {#2031 ▶}
"2019-10-26" => Collection {#2032 ▶}
"2019-10-27" => Collection {#2033 ▶}
"2019-10-28" => Collection {#2034 ▶}
"2019-10-29" => Collection {#2035 ▶}
]
}
kindly some one help pleaseee
in my blade file i need to use two forloops like below
//this displayes the date in column wise like 10 11 12 like this
@foreach($attendances as $key => $attendance)
<th>{{ \Carbon\Carbon::parse( $key)->format('d') }}</th>
@endforeach
//this is for displaying the other data.
@foreach ($attendance as $value)
<tr>
<td>{{ $loop->iteration }}</td>
<td> {{ $value->staff->user_name}} </td>
<td> {{ $value->att_count}} </td>
</tr>
@endforeach
But i cant get it everything is collapsing. what may be the problem. i know that tr td will be an issue. but cant get it.
did my fetch query is right?? else need to change there anything