Request a form with Standard not working

Asked

Viewed 675 times

3

I’m making a request from my controller for a form in the view, is giving this error. I tried several methods, but none solved.

Estou fazendo um request do meu controller para um formulário na view, está dando esse erro.

Controller:

public function store(Request $request)
{
    $NomeDaEmpresa = $request->input('NomeDaEmpresa');
    $nCompartilhamentos = $request->input('nCompartilhamentos');
    $valorPorShare = $request->input('valorPorShare');
    $eMail = $request->input('email');

    //Preco a pagar sem a taxa
    $PrecoaPagarST = $nCompartilhamentos * $valorPorShare;
    //Preco a pagar com a taxa (20%)
    $PrecoaPagarTotal = $PrecoaPagarST * 1.20;

    return view('EnviarAnuncio');
  }
 }

Form:

<form role="form" action="/enviaranuncio" method="post">
                        <div class="form-group">
                            <label class="control-label" for="exampleInputEmail1">Nome da empresa</label>
                            <input class="form-control" id="exampleInputEmail1" placeholder="Digite o nome da empresa" type="text" value="" name="NomeDaEmpresa">
                        </div>
                        <div class="form-group">
                            <label class="control-label" for="exampleInputPassword1">Número de compartilhamento desejado</label>
                            <input class="form-control" id="exampleInputPassword1" placeholder="Número de shares" type="text" value="" name="nCompartilhamentos">
                        </div>
                        <div class="form-group">
                            <label class="control-label">Valor por share a pagar</label>
                            <input class="form-control" type="text" placeholder="Valor a pagar por share. Ex: 0.10" value="" name="valorPorShare">
                        </div>
                        <div class="form-group">
                            <label class="control-label">E-mail</label>
                            <input class="form-control" type="email" placeholder="Digite seu email" name="email" value="">
                        </div>
                        <button type="submit" class="btn btn-default">Criar Anúncio</button>
                    </form>

2 answers

7


Whenever you set a form you have to pass the CSRF token to Laravel to validate the request.

So add the following after the tag <form>:

{{ csrf_field() }}

More info: https://laravel.com/docs/5.3/csrf

2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.