Answer the question
In order to leave comments, you need to log in
Laravel5 + dropzone js files not validating?
Good afternoon! I use the dropzone.js library to upload files and everything works with a bang if you do not use laravel validation for uploaded files. Below is the validation code and the download method
public function upload(UplloadNewGalleryFiles $request)
{
$input = $request->all();
$gallery = new gallery();
$title = $input['title'];
$directoryName = parent::randomName(24);
$disk = Storage::disk('gallery');
if($disk->makeDirectory($directoryName))
{
$gallery->title = $title;
$gallery->folder = "images/gallery/$directoryName";
$gallery->created_at = Carbon::now();
$gallery->save();
}
foreach( $input['file'] as $file )
{
$ext = $file->getClientOriginalExtension();
$name = parent::randomName(24) . ".$ext";
$file->move( "images/gallery/$directoryName" , $name);
$galleryFile = new files();
$galleryFile->gallery = $title;
$galleryFile->name = $name;
$galleryFile->extention = $ext;
$galleryFile->created_at = Carbon::now();
$galleryFile->save();
}
}
public function rules()
{
return [
'title' => 'unique:gallery,title',
'file' => 'required|mimes:jpeg,bmp,png',
//
];
}
{"file":["The file must be a file of type: jpeg, bmp, png."]}
Answer the question
In order to leave comments, you need to log in
There is a magic "asterisk" for working with arrays in validation.
In your case check each file in $request->file array -
$this->validate($request, [
'file.*' => 'required|mimes:jpeg,bmp,png'
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question