Laravel 4 表单提交

3

我目前正在学习 Laravel 4。

我试图创建一个非常简单的文章表单,这是我的表单开头代码:

{{ Form::open(array('post' => 'NewQuoteController@quote')) }}

然后在我的NewQuoteController中,我有以下内容:

public function quote() {

   $name = Input::post('ent_mileage');
   return $name;

}

我一直收到以下错误提示:

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

可能是非常愚蠢的问题...谢谢。

编辑

这是我在routes.php中的内容。

Route::get('/newquote','NewQuoteController@vehicledetails');

Route::post('/newquote/quote', 'NewQuoteController@quote');
2个回答

9

对于POST请求,您需要将其改为:

{{ Form::open(array('action' => 'NewQuoteController@quote')) }}

你需要为控制器动作设置一个路由:

Route::post('quote', 'NewQuoteController@quote');
<开启翻译>

Form::open() 的默认方法是 POST,但如果你需要将其更改为 PUT,则需要进行以下操作:

{{ Form::open(array('method' => 'PUT', 'action' => 'NewQuoteController@quote')) }}

你还需要为它创建一个新路由:

Route::put('quote', 'NewQuoteController@quote');

你还需要更改。
$name = Input::post('ent_mileage');

$name = Input::get('ent_mileage');

您可以使用相同的URL来处理不同的方法和操作:
Route::get('/newquote','NewQuoteController@vehicledetails');

Route::post('/newquote', 'NewQuoteController@quote');

Route::put('/newquote', 'NewQuoteController@quoteUpdate');

仍然得到相同的结果,我忘记添加,当我提交表单时会收到这个消息... - WebDevB
你也在使用这个路由时遇到了这个错误吗?检查生成的HTML代码。获取<FORM>行并将其粘贴到pastebin上,或者编辑你的消息。 - Antonio Carlos Ribeiro
<form method="POST" action="http://localhost:8888/l4_site/public/newquote/quote" accept-charset="UTF-8"><input name="_method" type="hidden" value="PUT"><input name="_token" type="hidden" value="ej7Wk63SHHM2OWyzqo6o6dz5E8rI5cBVckZdPjcc"> - WebDevB
成功运行了,没有出现错误,但是由于某些原因输入内容没有被传递过来,这个问题我现在可以先不用担心。 :-) - WebDevB
如果你执行 dd(Input::all()) 却什么都没有输出? - Antonio Carlos Ribeiro
显示剩余8条评论

1
你尝试过将表单开放方式更改为什么吗?
{{Form::open(['method'=>'POST', 'route' =>'NewQuoteController@quote')}}

在你的控制器中,可以使用 Input 方法之一访问表单输入内容吗?
public function quote() {

    $name = Input::get('ent_mileage');

    return $name; 
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接