简体   繁体   中英

laravel 5.1 form and routing issue

Hi i am trying to get the output from my form to save and even when i try to echo(print_r) the output it but it simply goes to the post request and does not echo any output.

my route looks like:

Route::controller('stove', 'StoveController', [
    'anyData'  => 'stove.data',
    'getIndex' => 'stove',
]);

Route::get('newstove', 'StoveController@addData');
Route::post('newstove', 'StoveController@store');

my controller:

public function addData()
{

    return view('stoves.new');
}

public function store()
{
    $input = Request::all();
    Stove::create($input);

    return redirect('stove');
}

and finally my form is

<form class="form-horizontal" action="/stove">
    <fieldset>
        <div class="control-group">
            <label class="control-label" for="stoveno">Stove Number</label>
            <div class="controls">
                <input type="text" class="span4" id="stoveno" value="CP001000">
            </div> <!-- /controls -->
        </div> <!-- /control-group -->

        <div class="control-group">
            <label class="control-label" for="refno">Ref Number</label>
            <div class="controls">
                <input type="text" class="span4" id="refno" value="cff001">
            </div> <!-- /controls -->
        </div> <!-- /control-group -->

        <div class="control-group">
            <label class="control-label" for="manufacturedate">Manufacture Date</label>
            <div class="controls">
                <input type="date" class="span4" id="manufacturedate">
            </div> <!-- /controls -->
        </div> <!-- /control-group-->

        <div class="form-actions">
            <button type="submit" class="btn btn-primary">Save</button>
            <button class="btn">Cancel</button>
        </div> <!-- /form-actions -->
    </fieldset>
</form>

Thanks

Change the first line of your form to the following..

<form class="form-horizontal" action="/newstove" method="post">

This should submit your form via the POST method to the last route in your routes file.

From what I can see the first part of your routes file is not required...

Route::controller('stove', 'StoveController', [
   'anyData'  => 'stove.data',
   'getIndex' => 'stove',
]);

Route::post('newstove', 'StoveController@store');

You need to add method="post" to the form. and change the action="/stove" to action="/newstove"

Also, isn't it Route::resource for adding controllers to the route list?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM