Guest User

Untitled

a guest
Apr 18th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. <form class="form-horizontal" method="post" action="{{url('/usuarios')}}">
  2. @csrf
  3.  
  4. @if(session()->has('message'))
  5. <div class="callout callout-danger">
  6. {{ session()->get('message') }}
  7. </div>
  8. @endif
  9.  
  10. <div class="box-body">
  11.  
  12. <div class="form-group has-feedback {{ $errors->has('tipo') ? 'has-error' : '' }}">
  13. <label for="tipo" class="col-sm-2 control-label">Tipo</label>
  14. <div class="col-sm-10">
  15. <select id="tipo" class="form-control" name="tipo" required>
  16. <option value="" selected>--- Escolha um tipo ---</option>
  17. @foreach($tipos as $tipo)
  18. <option value="{{ $tipo->id }}">{{$tipo->nome}}</option>
  19. @endforeach
  20. </select>
  21. @if ($errors->has('tipo'))
  22. <span class="help-block">
  23. <strong>{{ $errors->get('tipo')[0] }}</strong>
  24. </span>
  25. @endif
  26. </div>
  27. </div>
  28.  
  29. <div class="form-group has-feedback {{ $errors->has('name') ? 'has-error' : '' }}">
  30. <label for="name" class="col-sm-2 control-label">Usuário</label>
  31. <div class="col-sm-10">
  32. <input type="text" class="form-control" name="name" placeholder="" minlength="4" maxlength="50" required>
  33. @if ($errors->has('name'))
  34. <span class="help-block">
  35. <strong>{{ $errors->get('name')[0] }}</strong>
  36. </span>
  37. @endif
  38. </div>
  39. </div>
  40.  
  41. <div class="form-group has-feedback {{ $errors->has('email') ? 'has-error' : '' }}">
  42. <label for="email" class="col-sm-2 control-label">Email</label>
  43. <div class="col-sm-10">
  44. <input type="emais" class="form-control" name="email" id="email" placeholder="" minlength="7" maxlength="50" required>
  45. @if ($errors->has('email'))
  46. <span class="help-block">
  47. <strong>{{ $errors->get('email')[0] }}</strong>
  48. </span>
  49. @endif
  50. </div>
  51. </div>
  52.  
  53. <div class="form-group has-feedback {{ $errors->has('password') ? 'has-error' : '' }}">
  54. <label for="password" class="col-sm-2 control-label">Senha</label>
  55. <div class="col-sm-10">
  56. <input type="text" class="form-control" name="password" id="password" placeholder="" minlength="6" maxlength="50" required>
  57. @if ($errors->has('password'))
  58. <span class="help-block">
  59. <strong>{{ $errors->get('password')[0] }}</strong>
  60. </span>
  61. @endif
  62. </div>
  63. </div>
  64.  
  65. <div class="form-group has-feedback {{ $errors->has('cidadao') ? 'has-error' : '' }}">
  66. <label for="cidadao" class="col-sm-2 control-label">Cidadão</label>
  67. <div class="col-sm-10">
  68. <select id="cidadao" class="form-control" name="cidadao" required>
  69. <option value="" selected>--- Escolha um cidadão ---</option>
  70. @foreach($cidadaos as $cidadao)
  71. <option value="{{ $cidadao->id }}">{{$cidadao->nome}}</option>
  72. @endforeach
  73. </select>
  74. @if ($errors->has('cidadao'))
  75. <span class="help-block">
  76. <strong>{{ $errors->get('cidadao')[0] }}</strong>
  77. </span>
  78. @endif
  79. </div>
  80. </div>
  81.  
  82. </div>
  83.  
  84. <div class="box-footer">
  85. <button type="submit" class="btn btn-primary pull-right">Salvar</button>
  86. </div>
  87.  
  88. </form>
  89.  
  90. public function store(Request $request)
  91. {
  92. $v = Validator::make($request->all(), [
  93. // user
  94. 'tipo' => 'required|integer|not_in:--- Escolha um tipo ---',
  95. 'name' => 'required|string|min:4|max:50|unique:users',
  96. 'email' => 'required|string|email|min:7|max:50|unique:users',
  97. 'password' => 'required|string|min:4|max:50',
  98. 'cidadao' => 'required|integer|not_in:--- Escolha um cidadão ---',
  99. ]);
  100.  
  101. if($v->fails()) {
  102. return back()->with('message', 'Confira os dados informados!')->withErrors($v)->withInput();
  103. }
  104.  
  105. $user = new user;
  106. $user->name = $request->name;
  107. $user->email = $request->email;
  108. $user->password = Hash::make($request->password);
  109. $user->tipo_id = $request->tipo;
  110. $user->cidadao_id = $request->cidadao;
  111. $user->save();
  112. return redirect('/usuarios')->with('message', 'Cadastro realizado com sucesso!');
  113. }
Add Comment
Please, Sign In to add comment