
That fetch data code

model
* @param Request $request
*/
public function uploadFiles(Request $request)
{
if(!$request->ajax()) {
abort(404);
}
$inputs = $request->all();
if(!isset($inputs[‘album_id’]) || $inputs[‘album_id’] == null) {
abort(404);
}
$albumID = $inputs[‘album_id’];
$result = Album::where(‘id’, $albumID)->first();
if($result == null) {
abort(404);
}
$galleryArr = [];
if($request->hasFile(‘file’)) {
$files = $request->file;
if(count($files) > 0) {
$destinationPath = public_path(‘uploads/gallery/’);
$thumbPath = public_path(‘uploads/thumbs’);
$xsThumbPath = public_path(‘uploads/xs-thumbs’);
foreach($files as $image) {
$originalName = $image->getClientOriginalName();
$extension = $image->getClientOriginalExtension();
$size = $image->getSize();
if(!in_array($extension, [‘jpg’, ‘jpeg’, ‘png’ , ‘gif’])) {
continue;
}
#Not more than 5MB.
if($size >= 5242880) {
continue;
}
$imageName = randomName(10) . ‘.’. $extension;
#saving thumbs
$thumbImg = Image::make($image->getRealPath())->resize(370, 280);
$thumbImg->save($thumbPath.’/’.$imageName, 80);
$xsThumbImg = Image::make($image->getRealPath())->resize(370, 280);
$xsThumbImg->save($xsThumbPath. ‘/’ .$imageName, 80);
$galleryArr[] = [
‘album_id’ => $albumID,
‘original_name’ => $originalName,
‘image’ => $imageName
];
$image->move($destinationPath, $imageName);
}
(new Gallery)->insert($galleryArr);
}
}
}




‘method’ => ‘POST’,
‘files’ => true,
‘enctype’ => ‘multipart/form-data’,
‘class’ => ‘dropzone’,
‘id’ => ‘my-dropzone’
])
}}
{{ Form::hidden(‘album_id’, $albumID, [‘id’ => ‘album_id’]) }}
{{ Form::close() }}
</div>
</div>
</div>
</div>
</div>
<!– /Row –>
</div> <!– end container –>
@endsection
@section(‘scripts’)
<script>
$(function(){
Dropzone.options.myDropzone = {
paramName: ‘file’,
acceptedFiles: ‘.jpg, .jpeg, .png’,
maxFiles:10,
parallelUploads: 100,
maxFilesize: 5,
uploadMultiple: true,
addRemoveLinks: true,
init:function() {
let myDropzone = this;
$.get(‘{{ route(‘server.image’, [‘id’ => $albumID]) }}’, function(data) {
$.each(data.images, function (key, value) {
var file = {name: value.original, size: value.size, file_name: value.server};
myDropzone.options.addedfile.call(myDropzone, file);
// myDropzone.options.thumbnail.call(myDropzone, file, ‘../uploads/thumbs/’ + value.server);
myDropzone.options.thumbnail.call(myDropzone, file, ‘../uploads/xs-thumbs/’ + value.server);
myDropzone.emit(“complete”, file);
});
});
myDropzone.on(‘sendingmultiple’, function(data, xhr, formData) {
// this will get sent
formData.append(‘album_id’, $(‘#album_id’).val());
// this won’t
let myForm = document.querySelector(‘form’);
formData = new FormData(myForm);
});
myDropzone.on(“removedfile”, function(file) {
$.ajax({
type: ‘POST’,
url: ‘{{ route(‘upload.delete’) }}’,
data: {
file_name: file.file_name,
_token: $(‘meta[name=”csrf-token”]’).attr(‘content’)
},
dataType: ‘html’,
success: function(data){
let response = JSON.parse(data);
if(response.status == 200) {}
}
});
} );
myDropzone.on(‘completemultiple’, function () {
window.location.reload();
});
}
};
});
</script>





‘album_id’ => $albumID,
‘original_name’ => $originalName,
‘image’ => $imageName
];
$image->move($destinationPath, $imageName);
}
(new Gallery)->insert($galleryArr);
‘album_id’,
‘original_name’,
‘image’
];



1. Laravel is returning Json you don’t need to convert it again
2. Please use the Axios library already included in your project





Check spatie media library
I know about this package but my project almost complete , i want finish this with this code