Malchesador
Malchesador

Reputation: 795

Laravel 4 Undefined Method Illuminate Http Request Request::post()

I have a simple html form and am calling a controller in the routes file, but upon submission I get the following error:

Symfony\Component\Debug\Exception\FatalErrorException thrown with message "Call to undefined method Illuminate\Http\Request::post()"

Stacktrace:
#1 Symfony\Component\Debug\Exception\FatalErrorException in /vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:205
#0 Illuminate\Exception\Handler:handleShutdown in <#unknown>:0

On this particular site, I have many forms and even more routes and all work except this one. I've looked again and again and again for some typo or something that might be causing it to fail, but can find nothing.

My form is:

<form class="form-horizontal" action="/warehouse/add_pallet" method="post" accept-charset="utf-8" role="form">
    <div class="row">
        <div class="col-xs-12">
            <div class="pm-well">   
                <h2>Scan Add Pallet</h2>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2" for="pallet_location">Location: </label>
                    <div class="col-xs-12 col-sm-8">
                        <input type="text" class="form-control" name="pallet_location" id="pallet_location">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-2" for="sku">sku: </label>
                    <div class="col-xs-12 col-sm-8">
                        <input type="text" class="form-control" name="sku" id="sku">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-xs-12">
            <input type="submit" class="pm-btn pm-btn-confirmation medium-btn" value="Add Pallet">
        </div>
    </div>
</form>

And in my routes file I have:

Route::post('warehouse/add_pallet', 'PalletController@insert');

As a control test, I setup just a straight PHP (no Laravel or any PHP framework) test site and copied the form and changed the form action to simply point to another php script where I could echo out the request method and the post data and that worked as expected.

I'm stumped at this point. Could this be a bug? I have seen lots of other posts about problems with Symfony's Request::[methods] not working.

Upvotes: 2

Views: 2766

Answers (1)

Merhawi Fissehaye
Merhawi Fissehaye

Reputation: 2837

I am guessing that you have called a method post() inside your controller as either Request::post() or Input::post(). You should use Input::get() instead. The keyword get in the Facade Input is not bound to the $_GET global array. So whether you are submitting data using GET or POST method, you should use Input::get('key') to retrieve them. However to make sure that the data you are fetching is submitted through the POST method, you can use the Request::method() == 'POST' or Request::isMethod('post') surrounding your code.

Upvotes: 2

Related Questions