dtbc37573 2015-12-19 18:25
浏览 75
已采纳

Laravel 5 - 验证为false时的MethodNotAllowedHttpException

Always when the validation fails, I get a MethodNotAllowedHttpException

routes.php

Route::post('download', 'UrlController@download');
Route::post('search', 'UrlController@search');

UrlController.php

public function download(DownloadRequest $request)
{
    dd($request->all());
}

DownloadRequest.php

public function authorize()
{
    return true;
}

 public function rules()
{
    return [
        'format' => 'required|between:1,13'
    ];
}

name.blade.php

{!! Form::open(['url' => 'download']) !!}

{!! Form::select('format', [
    'Please select format',
    'FormatGrp1' => [1 => 'best', 'p1','p2', 'p3', 'p4'],
    'FormatGrp2' => [6 => 'p5', 'p6']
]) !!}

When "Please select format" is chosen and the form is submitted, I always get this error because "Please select format" has value 0 and i specified values must be between 1 and 13. (Look at DownloadRequest.php)

Thanks for help!

  • 写回答

2条回答 默认 最新

  • dongqing4070 2015-12-19 22:46
    关注

    The error didn't come from the validation.

    It was because it called the URL to go back and display the errors. And this is the search method.

    So cause of the logic in search method the exception has been thrown.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化