Hello, I'm creating an attendance system but i'm stuck. I have 3 tables: users, attendance_schedules and marks. users has: id, first_name, group_name, status etc columns. attendance_schedules has: group_name, meeting_date etc columns (this table stores information about upcoming meetings). marks has: user_id, meeting_date, status etc columns (this stores a marked attendance)
On the day of a meeting attendance_schedules->meeting_date, I want to display all the users that belong to the same group. However, when a user is marked, it should change the button from 'mark' to 'marked' (i am using marked->status to check if it is marked)
- Display list of users base on their groups
- Check if the user is marked for that Particular day
- if the user is marked for that day (status = 1) then button show "Marked" else show "Mark"
Controller:
public function getUsersByMeetingGroup() {
$meeting_group = Request()->meeting_group; //from the views get url
$users = User::where('users.status', 1) // checks if user is active
->where('users.meeting_group', $meeting_group)
->leftjoin('marks', 'marks.user_id', '=', 'users.id')
->select('users.id', 'users.first_name','users.first_name','users.meeting_group','users.batch', 'users.state_code','marks.status', 'marks.meeting_date', 'marks.arrival_time')
->get();
return $users;
}
Index:
@php $date = date("Y-m-d"); @endphp
@if($user->cds_date != $date)
<button class="badge badge-primary border-0 p-2" type="submit" name="mark" value="mark">
<i class="fa fa-check"></i>
Mark
</button>
@else
<a class="badge badge-primary border-0 p-2">
Marked
<i class="fa fa-check-double"></i>
</a>
@endif
It still displays/duplicates users based on records of the user in marks table.
OUTPUT
--------------------------------
Name | Group | ********* | Action
John | Football | ********** | marked // previous record in the database
John | Football | ********** | mark
-------------------------------
How do i solve this problem?