courses = \App\Models\Course::orderBy('name')->get(); if (sizeof($this->courses) > 0) $this->courseId = $this->courses[0]->id; } public function render() { // Carico tutti i corsi associati $member_course = \App\Models\MemberCourse::where('course_id', $this->courseId)->with('member')->get(); $this->records = array(); foreach($member_course as $x) { $this->records[] = array( $x->member_id . "ยง" . $x->member->first_name . " " . $x->member->last_name, $this->getColor($x->months, 1), $this->getColor($x->months, 2), $this->getColor($x->months, 3), $this->getColor($x->months, 4), $this->getColor($x->months, 5), $this->getColor($x->months, 6), $this->getColor($x->months, 7), $this->getColor($x->months, 8), $this->getColor($x->months, 9), $this->getColor($x->months, 10), $this->getColor($x->months, 11), $this->getColor($x->months, 12) ); } return view('livewire.course_list'); } public function getColor($months, $m) { $class = "grey"; foreach(json_decode($months) as $mm) { if ($mm->m == $m) { if ($mm->status == "") { $class = "orange"; } if ($mm->status == "1") { $class = "green"; } if ($mm->status == "2") { $class = "yellow"; } } } return $class; } }