I have the students table, franchise_schedules and student_schedules. I need to make a schedule and show all students who are enrolled at a certain time.
I got this table (franchise_schedules):
And this table (student_schedule):
And I need to show all students at the same time (this is what I got now):
//Searching all hours:
$schedules = FranchiseSchedule::orderBy('start_time', 'ASC')
->where('franchise_id', $franchise->franchise_id)
->groupBy('day_week', 'start_time')
->get();
//Seeking the students of each time
foreach($schedules as $schedule){
$ob_schedules = (object)$schedule->toArray();
$monday = StudentSchedule::join('franchise_schedules', 'franchise_schedules.id', '=', 'student_schedules.franchise_schedule_id')
->join('students', 'students.id', '=', 'student_schedules.student_id')
->select('student_schedules.id as student_schedule_id', 'franchise_schedules.start_time as start_time', 'franchise_schedules.day_week as day_week', 'students.name as student_name')
->where('franchise_schedules.day_week', 1)
->where('student_schedules.franchise_schedule_id', $schedule->id)
->get();
$tuesday = StudentSchedule::join('franchise_schedules', 'franchise_schedules.id', '=', 'student_schedules.franchise_schedule_id')
->join('students', 'students.id', '=', 'student_schedules.student_id')
->select('student_schedules.id as student_schedule_id', 'franchise_schedules.start_time as start_time', 'franchise_schedules.day_week as day_week', 'students.name as student_name')
->where('franchise_schedules.day_week', 2)
->where('student_schedules.franchise_schedule_id', $schedule->id)
->get();
$wednesday = StudentSchedule::join('franchise_schedules', 'franchise_schedules.id', '=', 'student_schedules.franchise_schedule_id')
->join('students', 'students.id', '=', 'student_schedules.student_id')
->select('student_schedules.id as student_schedule_id', 'franchise_schedules.start_time as start_time', 'franchise_schedules.day_week as day_week', 'students.name as student_name')
->where('franchise_schedules.day_week', 3)
->where('student_schedules.franchise_schedule_id', $schedule->id)
->get();
$ob_schedules->monday = $monday;
$ob_schedules->tuesday = $tuesday;
$ob_schedules->wednesday = $wednesday;
array_push($ar_schedules, $ob_schedules);
}
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2KqUkia
via IFTTT
Aucun commentaire:
Enregistrer un commentaire