public function update_profil_post(Request $request, $id) { $user = Auth::user(); if ($user->profil->intitule == "administrateur") { $erreurs = new Collection(); $this->validate($request, ['intitule' => 'required']); $profils = Profil::all(); $profil = Profil::find($id); foreach ($profils as $p) { if ($request->input('intitule') != $profil->intitule) { if ($request->input('intitule') == $p->intitule) { $erreurs->prepend("Cet intitulé existe déjà !"); break; } } } $profil->intitule = $request->input('intitule'); if (count($erreurs) > 0) { return response()->view('profil/update_profil', ['profil' => $profil, 'erreurs' => $erreurs]); } $profil->save(); return redirect('admin/profil'); } return "Vous êtes pas administrateur"; }
public function update_user_post(Request $request, $id) { $user = Auth::user(); if ($user->profil->intitule == "administrateur") { $erreurs = new Collection(); $this->validate($request, ['nom' => 'required', 'prenom' => 'required', 'mail' => 'required', 'login' => 'required|min:8', 'mdp2' => 'min:8', 'profil' => 'exists:profil,id']); $user = User::find($id); $users = User::all(); foreach ($users as $u) { if ($request->input('login') != $user->login) { if ($request->input('login') == $u->login) { $erreurs->prepend("Ce login existe déjà !"); break; } } } foreach ($users as $u) { if ($request->input('mail') != $user->mail) { if ($request->input('mail') == $u->mail) { $erreurs->prepend("Cet email existe déjà !"); break; } } } $user->parcours_id = null; $user->groupe_id = null; $user->profil_id = null; $user->nom = $request->input('nom'); $user->prenom = $request->input('prenom'); $user->mail = $request->input('mail'); $user->login = $request->input('login'); if ($request->input('mdp2')) { $user->mdp = $request->input('mdp2'); } if ($request->input('actif') == 1) { $user->actif = $request->input('actif'); } else { $user->actif = 0; } if ($request->input('parcours') != 0) { $user->parcours_id = $request->input('parcours'); } if ($request->input('groupe') != 0) { $user->groupe_id = $request->input('groupe'); $user->parcours_id = Groupe::find($request->input('groupe'))->parcours->id; } if (count($erreurs) > 0) { $parcours = Parcours::all(); $profils = Profil::all(); $groupes = Groupe::all(); $ues = Ue::all(); return response()->view('auth/update_compte', ['erreurs' => $erreurs, 'parcours' => $parcours, 'profils' => $profils, 'groupes' => $groupes, 'ues' => $ues, 'user' => $user]); } if ($request->input('profil') != 0) { $user->profil_id = $request->input('profil'); } $user->save(); if (count($request->input('ues')) > 0) { $user->uesEnseignees()->detach(); foreach ($request->input('ues') as $ue_id) { $enseigner = new Enseigner(); $enseigner->user_id = $user->id; $enseigner->ue_id = $ue_id; $enseigner->save(); } } return redirect('admin/user'); } return "Vous êtes pas administrateur"; }
<h2>PAGE DE GESTION DES UTILISATEURS</h2> <div style="position:fixed; z-index:100000; display:none;" id="filtrage" class="col-sm-offset-3 col-sm-6"> <div class="panel panel-info"> <div class="panel-heading">CHOIX DE PROFIL {!! Form::open(['url' => 'admin/user']) !!} </div> <div class="panel-heading">Type de profil</div> <div class="panel-body"> <div class="form-group"> <select onChange="checkProfil(this);" name="profil"> <option value="0">Choissir tout</option> <?php $profils = \App\Profil::all(); ?> @if (isset($profils)) @foreach ($profils as $profil) <option value="{{ $profil->id }}">{{ $profil->intitule }}</option> @endforeach @endif </select> </div> </div> <div id="parcours1" class="panel-heading">Année suivie</div> <div id="parcours2" class="panel-body"> <div class="form-group"> <select name="parcours">
public function index() { $profil = Profil::all(); return response()->json(['data' => $this->transformCollection($profil)], 200); }