Laravel 5.6 recover data from a form?

Asked

Viewed 700 times

0

Error

Symfony Component Httpkernel Exception Methodnotallowedhttpexception

No message

Method in the Controller

class GuzzleController extends Controller
{
    public function post(Request $request){
    $email = $request->input('email');
    $senha = $request->input('senha');

    dd($email,$senha);
}

web php.

Route::get('/post', 'GuzzleController@post');

index php.

Note: here I get lost

<body>
    <form action="/post" method="POST">
         E-mail: <input type="text" name="email"><br>   
         senha: <input type="text" name="senha"><br>
         <input type="submit">
    </form>
</body>
  • Because you are editing your index.php?

  • I don’t understand your question

  • Your view is called ìndex.php? It is inside the public folder that html ?

  • No, it’s just a name I’ve defaulted to, within Resources views index.blade.php

  • when I call the método la no controller and I try to get the data of the form it gives this error , Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException&#xA;No message

  • 3

    Change your route to post: Route::post

  • @diegoViera opa , I changed and changed the error now this The page has expired due to inactivity. &#xA;&#xA;Please refresh and try again. I have already closed everything and opened again , I have restarted the server

  • Isn’t one missing } to close the function post in the GuzzleController?

Show 3 more comments

1 answer

2


On the routes change this way

Route::any('/post', 'GuzzleController@post')->name('postForm');

The Route::any will pick up all the methods and how you want just the POST can put

Route::post

Another good thing is to put a name in your routes, so you can change the URL dynamically, without having to change in multiple files.

Don’t forget the CSRF token, is needed in Laravel, in requisitions POST

<form method="POST" action="{{route('postForm')}}">
@csrf
  E-mail: <input type="text" name="email"><br>   
     senha: <input type="text" name="senha"><br>
     <input type="submit">
</form>

Try putting the name of view as index.blade.php

  • 1

    Great Explanation , I could understand ! , I just had to change one thing to work , I tried to use action="{{route('/post')}}"> he says that n("Route [{$name}] not defined."); so I did straight action="/post"

  • the route() helper only allows calling the route name

  • Example Route::any('/post', 'Guzzlecontroller@post')->name('postForm'); see at the end the method name(); ai at route you call route('postForm')

  • So when changing the url of your route you won’t need to keep updating in the code

Browser other questions tagged

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