/** * Display a listing of the resource. * * @return Response */ public function index() { if (Auth::check() && Auth::user()->roles == 'admin') { $users = User::sorted()->paginate(20); $users = Table::create($users, ['id', 'firstname', 'name', 'email']); $users->addColumn('roles', 'Roles', function ($model) { if ($model->roles == 'admin') { $icon = "<i class='material-icons'>build</i>"; } else { $icon = "<i class='material-icons'>face</i>"; } return $icon; }); $users->addColumn('created_at', 'Depuis', function ($model) { return $model->created_at->format('d M Y - H:i'); }); $users->addColumn('id', 'Editer', function ($model) { $url = route('profile', ['id' => $model->id]); echo "<a href='{$url}'><i class='material-icons'>create</i></a>"; }); return view('users/index')->with('users', $users); } else { abort(403, 'Unauthorized action.'); } }
/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(Request $request, $id) { $user = User::find($id); $parameters = $request->except(['_token']); //dd($request->all()); if (strlen($parameters['password']) == 0) { $validator = Validator::make($request->all(), ['email' => 'required|email|unique:users,email,' . $id . '|max:100', 'corrective' => 'required', 'prandial' => 'required']); } else { $validator = Validator::make($request->all(), ['email' => 'required|email|unique:users,email,' . $id . '|max:100', 'corrective' => 'required', 'prandial' => 'required', 'password' => 'required|confirmed|min:6']); } if ($validator->fails()) { return redirect()->route('profile', ['id' => $id])->withErrors($validator)->withInput(); } $user->email = $parameters['email']; $user->corrective = $parameters['corrective']; $user->prandial = $parameters['prandial']; if (strlen($parameters['password']) != 0) { $user->password = bcrypt($parameters['password']); } $user->save(); return redirect()->route('profile', ['id' => $id])->with('success', 'Your profile was updated !'); }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { return User::create(['firstname' => $data['firstname'], 'name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]); }