file upload - Image validation not working If using ajaxForm -


i tried googling , saw other questions posted @ forum not find solution issue. using jquery ajaxform method submit form. form contains 1 file field in form can used upload picture. have defined validation in model. issue uploading correct jpg file, still getting error message

argument 1 passed illuminate\\validation\\factory::make() must of type array, object given. 

javascript code

$('#create_form').ajaxform({     datatype:'json',     success: function(response){         alert(response);         }  }).submit(); 

controllder code

if ($file = input::file('picture')) {     $validator = validator::make($file, user::$file_rules);      if ($validator->fails()) {         $messages = $validator->messages();         foreach ($messages->all(':message') $message) {             echo $message; exit;         }         return response::json(array('message'=>$response, 'status'=>'failure'));     } else {         // rest      } } 

model code

public static $file_rules = array(     'picture' => 'required|max:2048|mimes:jpeg,jpg,bmp,png,gif' ); 

post request

enter image description here

i know validation defined in model expects array. passing $file in validator, object passed. changed code like:

$validator = validator::make(array('picture' => $file->getclientoriginalname()), user::$file_rules); 

now getting error:

the picture must file of type: jpg, jpeg, png,gif. 

the problem pass file object directly validate. validator::make() method takes 4 parameters array. moreover, need pass whole file object value validator can validate mime type, size, etc. that's why code should that.

$input = array('picture' => input::file('picture')); $validator = validator::make($input, user::$file_rules);  if ($validator->fails()) {     $messages = $validator->messages();     foreach ($messages->all(':message') $message) {         echo $message; exit;     }     return response::json(array('message'=>$response, 'status'=>'failure')); } else {     // rest  } 

hope useful you.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -