Guest User

Untitled

a guest
Feb 18th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. public function rules()
  2. {
  3. return [
  4. 'login' => 'required|max:255|alpha_dash',
  5. 'pass' => 'required|min:6|max:255|same:pass_conf',
  6. 'pass_conf' => 'required',
  7. ];
  8. }
  9.  
  10. public function messages()
  11. {
  12. return [
  13. 'login.required' => 'Поле ввода не должно быть пустым или иметь пробелы',
  14. 'login.max' => 'Логин не может содержать больше 255 символов',
  15. 'login.alpha_dash' => 'Поле можно содержать только алфавитные символы, цифры, знаки подчёркивания "_" и дефисы "-"',
  16. 'pass.required' => 'Поле ввода не должно быть пустым или иметь пробелы',
  17. 'pass.min' => 'Пароль должен содержать не менее 6 символов',
  18. 'pass.max' => 'Пароль не может содержать больше 255 символов',
  19. 'pass.same' => 'Пароли не совпадают!',
  20. 'pass_conf.required' => 'Поле ввода не должно быть пустым или иметь пробелы',
  21. ];
  22. }
  23.  
  24. <form class="form-horizontal" method="POST" action="{{ route('setusername') }}" >
  25. {{ csrf_field() }}
  26.  
  27. <div class="form-group">
  28. <label for="login" class="control-label">Изменить текущий логин</label>
  29. <input type="text" class="form-control mr-sm-2 mb-2" id="login" name="login" placeholder="Введите новый логин">
  30. <button type="submit" class="btn btn-primary">Изменить</button>
  31. </div>
  32.  
  33.  
  34.  
  35. @if ($errors->any()) {{-- Вывод сообщений о некорректном вводе --}}
  36. <div class="alert alert-danger inline-block mt-1">
  37. <ul>
  38. @foreach ($errors->get('login') as $message)
  39. <li>{{ $message }}</li>
  40. @endforeach
  41. </ul>
  42. </div>
  43. @endif
  44. </form>
  45.  
  46. public function setusername(ProfileValidationRequest $request)
  47. {
  48. $username = $request->login;
  49.  
  50. Auth::user()->name = $username;
  51. Auth::user()->save();
  52. return redirect('/profile');
  53. }
  54.  
  55. public function setpassword(ProfileValidationRequest $request)
  56. {
  57. $password = Hash::make($request->pass);
  58.  
  59. Auth::user()->password = $password;
  60. Auth::user()->save();
  61. return redirect('/profile', $password);
  62. }
  63.  
  64. Route::post('profile.setusername', 'ProfileController@setusername')->name('setusername');
  65. Route::post('profile.setpass', 'ProfileController@setpassword')->name('setpass');
  66.  
  67. protected $errorBag = 'login';
  68.  
  69. $errors->login
Add Comment
Please, Sign In to add comment