Laravel search function returns Tokenmismatchexception error in Verifycsrftoken.php

Asked

Viewed 304 times

1

Good evening friends, I am new to the Laravel and I need to build a function for data search of a table, I did something based on what I understood so far, but this returning me the following error message **Tokenmismatchexception in Verifycsrftoken.php line 67:**when the route is requested. below follows the code:

Routes.php

Route::post('clientes/pesquisa', 'ClientesController@pesquisa');

Clientescontroller.php

public function pesquisa(){
        $pesq = Input::get('pesq');
        $resultado = Tb_clientes::where('idempresa', 1)->where('nome', '=',$pesq)->get();
        return view('clientes.index')->with('tb_clientes', $resultado);
    }

The call place of the route

<form class="form-inline" method="post" role="form" action="/clientes/pesquisa">
                          <div class="form-group">
                            <label >Pesquisar:</label>
                            <input type="text" class="form-control input-sm" id="pesq">
                          </div>
                          <button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-search"></button>
                        </form>

I’m doing it right or there’s an easier way?

  • Welcome to Sopt. Go to Help and take the Tour. Here in case of this issue you need to present part of your code. Edit the question and enter the code below it. It will be easier to help you.

  • 1

    Edited. Thank you

  • Perfect! Nice work! Be sure to mark the answer that served you in some way (or the best among them) and vote on the questions and answers that are important leave you.

2 answers

1

Guys is already solved just put input

<input type="hidden" name="_token" value="{{ csrf_token() }}">

worked out!

  • I’m glad you made it, your question got better after the amendments.

1


Your first and most important step is to read as much of official documentation (if not the entire documentation), believe me, the documentation is and always will be your best company.

Before doing a survey you should learn how to build a new application from scratch, set your application’s initial settings and configure your development environment. I can say that you will need to define and configure your database, your basic routes, your templates, and only then create, read, update and delete this data.

With regard to our community, I would like to welcome you and reinforce a section of the introductory text which reads as follows::

Focus your attention on questions about a real problem that you faced. Include details about what you tried and exactly what you’re trying to make.

Your question is very simple and incomplete, try to inform us what you have tried and in which points you are in the most difficulties. Don’t forget to use the search up there to search for related questions that might also work for you (try our good old friend Google).

If you are still in trouble, try to edit your question and add more details.

I hope this has helped you in some way, I will leave some interesting links that I found with a simple Google search, related to Laravel.

And I couldn’t help pointing out Laracasts.

  • Okay, thank you very much Rafael, I will first take a look at the documentation as indicated, I have already set up database routes and etc, I just need to implement the search on a page, but first I will take another look and if I can not put here what I tried. Thank you

  • Combined @Filipeguedes, once again welcome to our community. One more suggestion, see if you can follow the official documentation tutorial where you build a simple (or advanced) task list.

Browser other questions tagged

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