Esempio n. 1
0
 /**
  * Save a user.
  *
  * @return Redirect
  */
 public function store(Request $request)
 {
     // validate
     $this->validate($request, ['first_name' => 'required', 'email' => 'required|email|unique:users', 'password' => 'required']);
     // store
     $user = new user();
     $user->first_name = $request->first_name;
     $user->last_name = $request->last_name;
     $user->email = $request->email;
     $user->admin = 1;
     $user->password = Hash::make($request->password);
     $user->save();
     // redirect
     $request->session()->flash('success', trans('users.user') . ' ' . trans('crud.created'));
     return redirect('admin/users/' . $user->id . '/edit');
 }
 public function update(Request $request)
 {
     $post = $request->all();
     $validator = user::validateUpdateData($post);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator->errors());
     } else {
         $currentpassword = \Auth::user()->password;
         if (\Hash::check($post['password'], $currentpassword)) {
             unset($post['_token'], $post['password']);
             $result = user::where('id', $post['id'])->update($post);
             if ($result > 0) {
                 Flash::success('Profile successfully updated');
             }
             return redirect('admin');
         } else {
             return redirect()->back()->withErrors('Wrong Password');
         }
     }
 }
Esempio n. 3
0
 public function aexcel()
 {
     Excel::create('Listado de Usuario', function ($excel) {
         $excel->sheet('Usuarios', function ($sheet) {
             /*$products = Product::all();*/
             $users = user::select('id', 'name', 'username', 'email', 'type', 'active')->get();
             $sheet->fromArray($users);
         });
     })->download('xls');
 }