Advertisement
leonsuke

try.. catch..

Jan 17th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. public function update($id, Request $request) {
  2. $rules = array(
  3. 'email' => 'required|email', // make sure the email is an actual email
  4. 'password' => 'required|alphaNum|min:3', // password can only be alphanumeric and has to be greater than 3 characters
  5. 'konfirmasi_password' => 'required|same:password'
  6. );
  7.  
  8. // run the validation rules on inputs from the form
  9. $validator = Validator::make($request->all(), $rules);
  10.  
  11. if ($validator->fails()) {
  12. // Error
  13. $request->session()->flash('warning_ubah', 'Password tidak sama. Silahkan mencoba kembali. Terima kasih.');
  14. return redirect()->back();
  15. } else {
  16. try {
  17. $data = UsersModel::find($id);
  18. $input = $request->all();
  19. $data->fill($input)->save();
  20. } catch(Exception $e) {
  21. // Error
  22. }
  23.  
  24. $request->session()->flash('success_ubah', 'Data berhasil diganti. Terima kasih.');
  25. return redirect()->back();
  26. }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement