I'm playing with laravel and then came the following doubt. I need to get a variable that is in the controller and put it inside a view. In case I am sending an email with data contained in a form.
Basically this is how the user types the information in the form field when clicking on send the controller receives the variables from within the form validates and sends the email. The problem is that the email view is empty. I need to get these variables from the controller and put it in another view, this being the email view. VIEW THE FORM.
<section class="form-content content-bottom wow fadeIn" data-wow-duration="0.9s">
<h4>Envie-nos uma mensagem</h4> <br>
<div class="container">
<div class="row wow fadeIn" data-wow-duration="1.0s">
<form class="col s12" name ="form1" role="form" method="POST" action="{{ action('ContatoController@enviar') }}" >
{{ csrf_field() }}
<div class="row">
<div class="input-field col s12 m6 l6">
<input id="nome" type="text" class="validate" name="nome" required value="" placeholder="Nome Completo">
<label for="nome">Nome</label>
</div>
<div class="input-field col s12 m6 l6 ">
<input id="email" type="email" class="validate" name="email" required value="">
<label for="email">E-mail</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input id="phone" type="text" pattern="[0-9]+$" name="phone" required value="" minlength="10" maxlength="15" placeholder="telefone (DD)xxxx-xxxx ou celular (DD)9xxxx-xxxx *somente numeros">
<label for="phone">Telefone</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input id="assunto" type="text" name="assunto" required value="">
<label for="assunto">Assunto</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<textarea id="mensagem" name="mensagem" class="materialize-textarea" required value=""></textarea>
<label for="mensagem">Mensagem</label>
</div>
</div>
<div class="row center">
<div class="col s12">
<button type="submit" value="submit" class="btn login-button" onclick="return validar()">
Enviar
</button>
<br><br>
</div>
</div>
</form>
</div>
</div>
</section>
CONTROLLER
<?php
namespace App\Http\Controllers;
use App\Mail\msgformulario;
use App\Mail\msgfeedback;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use App\Http\Controllers\Controller;
class ContatoController extends Controller
{
public function enviar(request $request) {
$nome = $request->input('nome');
$email = $request->input('email');
$phone = $request->input('phone');
$assunto = $request ->input('assunto');
$mensagem = $request->input('mensagem');
if(isset($nome) && empty($nome)==false){
if(isset($email) && empty($email)==false){
if (isset($phone) && empty($phone)==false){
if (isset($assunto) && empty($assunto)==false){
if (isset($mensagem) && empty($mensagem)==false){
mail::to('[email protected]')->send(new msgformulario);
mail::to($email)->send(new msgfeedback);
$this->load->view('emails.formulario',$assunto);
return redirect('/contato');
}
}
}
}
}else{
return redirect('/contato');
}
}
}
?>
ROUTE:
Route::post('/feedback','ContatoController@enviar');
EMAIL VIEW (which should receive the variables to be filled in.)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Bem Vindo </title>
</head>
<body>
</body>
</html>