题
Hello im在laravel中新建,我无法从表单添加到数据库的数据。我只有一个形式的简单视图。控制器有2个操作(用于查看表单和创建DB行)。
app / partes.php
Route::get('/', 'FrontendController@index');
Route::post('/', 'FrontendController@submit');
.
app /视图/ index.blade.php
{{Form::open(array('action'=>'FrontendController@submit','class'=>'form-horizontal','role'=>'form'))}}
{{Form::text('nazev_firmy',Input::old('nazev_firmy'), array('class'=>'form-control'))}}
{{Form::submit('Send', array('class'=>'btn btn-primary submit'))}}
{{Form::close()}}
.
/app/controllers/frontendcontroller.php
class FrontendController extends BaseController {
public function index()
{
return View::make('index');
}
public function submit()
{
$inzerat = new Inzerat;
$inzerat->nazev_firmy = Input::post('nazev_firmy');
$inzerat->save();
return View::make('index');
}
}
app / model / inzerat.php
<?php
class Inzerat extends Eloquent {
protected $table = 'inzeraty';
public $timestamps = false;
}
.
错误单击提交按钮
Call to undefined method Illuminate\Http\Request::post()
.
Im使用Laravel 4.0
我在这里做错了什么?谢谢你的帮助。
解决方案
在Laravel中,您使用:: get()从请求中检索所有输入。你只需要改变
$inzerat->nazev_firmy = Input::post('nazev_firmy');
.
到:
$inzerat->nazev_firmy = Input::get('nazev_firmy');
. 不隶属于 StackOverflow