0
Well I have the code below
Validation:
class FormNew extends FormRequest{
public function authorize()
{
return true;
}
public function rules()
{
return [
'email' => 'required|email',
];
}
public function messages()
{
return [
'email.required' => 'campo Email Obrigatório',
'email.email' => 'campo Email com formato inválido',
];
}
}
Controller:
class FormularioController extends Controller{
public function newsletter(FormNew $request)
{
$usuarioEmail = Usuario::Where('email', $request->email)->first();
if($usuarioEmail == null){
$usuario = new Usuario;
$usuario->perfil_id = '2';
$usuario->email = $request->email ;
$usuario->password = Hash::make(rand(1,100).'senha');
$usuario->save();
return redirect('?#newsletters')->with('SucessoCadastro', 'Email Cadastrado com sucesso!');
}else{
return redirect('?#newsletters')->with('Falha', 'Email já cadastrado no sistema');
}
}
}
Note who in my redirect I am using an anchor, for when the user submits the form he goes straight to where the form is, I wanted to know how to use this redirect within my validation, for when the error is he go p form to show the errors (Formnew).
worked out, thank you very much!
– Schielke