samedi 19 décembre 2015

Laravel 5 - MethodNotAllowedHttpException when validation is false

Always when the validation fails, I get a MethodNotAllowedHttpException

routes.php

Route::post('download', ['uses' => '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!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire