【发布时间】:2018-05-02 14:10:42
【问题描述】:
我有 2 条路线:
Route::post('/post_2', 'TestController@post_2')
->name('post_2');
Route::post('/result', 'TestController@result')
->name('result');
和 TestController 如下。
public function post_2(){
return view('post_2View');
}
public function result(\App\Http\Requests\Post_2Request $request){
return "Successful";
}
Post_2查看
<form action="{{route('result')}}" method="post">
{{ csrf_field() }}
<input type="text" name="checkValidate">
<input type="submit" value="Submit">
</form>
最后一个是在 Post_2View 中验证 checkValidate 输入的请求
public function rules()
{
return [
'checkValidate'=>'required'
];
}
public function messages() {
return [
'checkValidate.required'=>"This field is required"
];
}
当我在 checkValidate 输入中有数据时,一切正常,但是当请求文件返回错误时,我在浏览器中看到错误
**
* Throw a method not allowed HTTP exception.
*
* @param array $others
* @return void
*
* @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
*/
protected function methodNotAllowed(array $others)
{
throw new MethodNotAllowedHttpException($others);
}
请告诉我,我该如何解决。 谢谢。
【问题讨论】:
-
帮自己一个忙,并从您的
result路由返回重定向,以避免混淆用于显示当前页面的方法。 -
您在哪里使用
post('/post_2'我的意思是当您将数据发布到/post_2时? -
这是我用来调用 post_2 的代码。
<form action="{{route('post_2')}}" method="POST"> {{ csrf_field() }} <input type="submit" value="Submit"> </form>
标签: laravel laravel-5 validate-request