我有一个可以上传多个文件的表单。我创建了一个UploadRequest来验证文件,但是在提交时没有任何反应,也没有抛出任何错误。我不知道为什么它不起作用或为什么它表现得像这样。
我的表格:
<?php echo Form::open(['url' => 'upload', 'files' => true]) ?>
<?php echo Form::token(); ?>
<div class="btn-group" data-toggle="buttons">
@foreach($data['damageTypes'] as $damageType)
<label class="btn btn-primary">
<?php
echo Form::radio('damageType', $damageType->id);
echo $damageType->name_nl;
?>
</label>
@endforeach
</div>
<?php echo Form::file('photos[]', ['multiple']); ?>
<?php echo Form::submit('Upload files', $attributes = ['class' => 'btn btn-info btn-lg btn-block']); ?>
<?php echo Form::close() ?>
@if (count($errors) > 0)
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
@endif
我的路线:
Route::post('upload', 'DamagePointController@uploadSubmit');
我的控制器和uploadsubmit动作
/**
* Handles the upload of the images.
*
* @return Response
*/
public function uploadSubmit(UploadRequest $request)
{
//
}
是的我use App\Http\Requests\UploadRequest;
我的上传请求
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$photos = count($this->input('photos'));
foreach(range(0, $photos) as $index) {
$rules['photos.' . $index] = 'image|mimes:jpeg,bmp,png|max:2000';
}
return $rules;
}
在理论中,当上传大于2000千字节的图像时,这应显示错误消息,但没有任何反应我被重定向到主页。