} } if (isset($_GET['id'])) { // on veux un étudiant avec un id précis. try { $id = (int) $_GET['id']; // on s'évite des possibles failles sql. $s = Student::findOrFail($id); // renvois une exception si l'étudiant n'existe pas. showItem($s->toArray()); } catch (ModelNotFoundException $e) { echo "Cet etudiant n'existe pas"; } } elseif (isset($_GET['showStudents'])) { // on veux afficher tous les étudiants. foreach (Student::all()->toArray() as $item) { showItem($item); echo "-----<br>"; } } elseif (isset($_GET['showGroups'])) { // on veux afficher tous les groupes. foreach (Groupe::all()->toArray() as $item) { showItem($item); echo "-----<br>"; } } elseif (isset($_GET['createStudent'])) { // on veux crer un étudiant $names = [["Alex", "Rose"], ["Art", "Rowland"], ["Barry", "Tad Keller"], ["Basil", "Abraham Lancaster"], ["Bob", "Garza"]]; $name = $names[rand(0, count($names) - 1)]; // on choisi un nom au hasard. /*
/** * affiche les étudiants */ public function students() { $listg = Student::all(); $vue = new VueEtu($listg->toArray()); $vue->render(1); }