app/Http/Controllers/UserController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(UserRequest $request)
    {
        try{
            $user = new User;
            $user->fill($request->except('idRol'));
            $faker = Faker\Factory::create();
            $password = $faker->password();
            $user->password = bcrypt($password);
            $user->save();
            $user->notify(new NewUserNotification($password));
            $user->roles()->attach($request->idRol);
            return redirect('usuarios')->with('success','Usuario creado');
        }catch(Exception | QueryException $e){
            return back()->withErrors(['exception'=>$e->getMessage()]);
        }
    }
public function store ( UserRequest $ request ) { try { $ user = new User ; $ user -> fill ( $ request -> except ( 'idRol' ) ) ; $ faker = Faker \ Factory :: create ( ) ; $ password = $ faker -> password ( ) ; $ user -> password = bcrypt ( $ password ) ; $ user -> save ( ) ; $ user -> notify ( new NewUserNotification ( $ password ) ) ; $ user -> roles ( ) -> attach ( $ request -> idRol ) ; return redirect ( 'usuarios' ) -> with ( 'success' , 'Usuario creado' ) ; } catch ( Exception | QueryException $ e ) { return back ( ) -> withErrors ( [ 'exception' => $ e -> getMessage ( ) ] ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .
//$user = User::create($request->except('idRol'));