exists()) { $identifiant = $base.$suffixe; $suffixe++; } return $identifiant; } public function genererCodeSecret(): string { return CodeLisible::genere(6); } /** * Crée le compte d'un élève et renvoie sa fiche (le code secret en clair * n'existe que dans cette fiche : il est stocké haché). * * @return array{eleve: Eleve, identifiant: string, prenom: string, nom: ?string, code_secret: string, jeton_qr: string} */ public function creerDans(Classe $classe, string $prenom, ?string $nom): array { $identifiant = $this->genererIdentifiant($prenom, $nom); $codeSecret = $this->genererCodeSecret(); $jetonQr = Str::random(32); $eleve = $classe->eleves()->create([ 'prenom' => $prenom, 'nom' => $nom, 'identifiant' => $identifiant, 'code_secret' => Hash::make($codeSecret), 'jeton_qr' => $jetonQr, ]); return ['eleve' => $eleve, 'identifiant' => $identifiant, 'prenom' => $prenom, 'nom' => $nom, 'code_secret' => $codeSecret, 'jeton_qr' => $jetonQr]; } }