我想验证文件输入字段,我是laravel的新手,所以我不知道缺少什么。
这是我的代码:
public function postUploadS(){
$file = array(Input::file('file'));
$rule = array('file' => 'required');
$validate = Validator::make($file,$rule);
if($validate->fails()){
var_dump($file); exit();
}
else{
return View::make('admin.uploadStaff'); }
}
即使我选择了文件,我也无法访问uploadStaff视图,如有任何帮助,请
您的问题似乎是$file
数组不关联,这意味着验证器看不到任何输入来比较$rule
中的file
规则。
更改:$file = array(Input::file('file'));
至:$file = array('file' => Input::file('file'));
验证器现在知道要根据您的规则运行什么输入。