1
Hello, I searched and did not find well what I was looking for for my Laravel project so I need help! I have a simple form that receives the name, email and a message from the user, but I would like to go through the database and check if the email is already in use and if it is in use display a message or alert.
So what logica should I use? how could I treat this? should I use Laravel’s own Validation?
I know I could assign in the database as UNIQUE in the desired field but I didn’t want to go this way.
BS: I’m learning Laravel
follows below the form code.
<form action="/project/public/enviar" method="POST">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<label for="nome">Nome</label>
<input type="text" id="nome" name="nome" class="form-control" placeholder="Nome">
</div>
<div class="form-group">
<label for="email">E-Mail</label>
<input type="text" id="email" name="email" class="form-control" placeholder="E-Mail">
</div>
<div class="form-group">
<textarea id="mensagem" name="mensagem" class="form-control" placeholder="Digite sua mensagem"></textarea>
</div>
<button type="submit" class="btn btn-default">Enviar</button>
</form>
Here is the View:
Route::post('/enviar', 'ContatoController@enviar')->middleware('auth');
Here is the Controller:
public function enviar(Request $request){
$contato = new Contato();
$contato->nome = $request->get('nome');
$contato->email = $request->get('email');
$contato->mensagem = $request->get('mensagem');
$contato->save();
As I said very simple but the more I need is making my hair stand on end, I thank you for your help.