dxcoder1
dxcoder1

Reputation: 299

validator function doesn't work in laravel

i want to validate the file input field, am new in laravel so i cant figure out what am missing.

here is my code:

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'); } 
     } 

I i cant get to the uploadStaff view even if i choose the file, any help please

Upvotes: 0

Views: 571

Answers (1)

wolfemm
wolfemm

Reputation: 1003

It looks like your problem is that the $file array isn't associative, meaning the validator doesn't see any input to compare the file rule in $rule against.

Change: $file = array(Input::file('file'));

to: $file = array('file' => Input::file('file'));

...and the validator now knows what input to run against your rule.

Upvotes: 1

Related Questions