public function simpanuser(UserRequest $request) { $input = $request->all(); $input['password'] = bcrypt($request->input('password')); try { User::create($input); $user = User::latest()->firstOrFail(); $role = Role::whereName($request->input('role'))->firstOrFail(); $user->attachRole($role); } catch (QueryException $e) { return redirect()->back()->with('error', 'Username yang anda masukkan sudah ada dalam database.'); } return redirect()->route('admin-user')->with('message', 'User baru telah ditambahkan...'); }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ public function create(array $data) { return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]); }