Form post does not work in Laravel 4

Asked

Viewed 353 times

0

I am trying to send the data of a form by the POST method, however it is not going at all

Just follow my code

// routes.php
Route::any('/', function()
{
    echo Request::getMethod();   // Aqui esta sempre retornando GET
    return View::make( 'login' );
});

// view/login.blade.php
<form action="{{URL::to('/')}}" method="post">
    <input name="login" type="text"/><br/>
    <input type="password" name="senha" id=""/><br/>
    {{ Form::submit('Enviar') }}
</form>

Regardless of whether the screen was loaded by the link or the Submit click, the return of Request::getMethod() is always being GET, consequently it has no data in the $_POST, because it happens this way?

  • I don’t think directing Route to any is the best alternative. You have some reason not to use a Route::get and a Route::post ?

  • Because I am trying to make the Login screen, for security reasons, I think I should use the POST

  • Lai, I believe it’s something you want to do, right? https://gist.github.com/gmsantosxl/feaedd41b7cdaff6304c

  • Exactly! but I’m doing router separately because I tried with Route::any and I couldn’t, for lack of knowledge, I’m afraid of being technical problems, so I decided to do it separately, but even so, Request::getMethod() is always returning me GET, you know why it happens this?

2 answers

1

Request::getMethod() returns the http (verb) method used in the request. Strange to be returning GET if you have posted to your html form.

To recover parameters sent in the request, you must use other commands:

Request::all() // retorna um array com todos os parâmetros

0

you came to give F12 and see if the post is being sent even, I think so. What’s wrong with your code is

Request::getMethod();

Think with me... If your form method is post, why do you think seeking getMethod() will return something beyond get?

i particularly use Input::all(), but have seen code using Request::all();

Then you just decide what’s best for you

  • It may be lack of knowledge of mine, but the Request::getMethod() function is not to return the method that was executed?

Browser other questions tagged

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