I am trying to send a set of data including image file through ajax using formdata but when I want to access that data in laravel controller, it shows a blank array.
Here is my ajax code -
var fd = new FormData();
fd.append("photo",files[0]);
fd.append("user_id",localStorage.getItem('userId'));
fd.append("doctype","dl_image");
console.log(fd);
//ajax code
$http.post('uploadfile', fd, {
withCredentials: true,
headers: { 'X-CSRF-TOKEN' : $('meta[name="csrf-token"]').attr('content') }
}).success(function(data, status) {
console.log(data);
});
PHP code -
$data = Request::all();
$photo = Request::file('photo');
$userid = Request::get('user_id');
$doctype = Request::get('doctype');
$postData = array(
'photo' => $photo,
'user_id' => $userid,
'doctype' => $doctype
);
var_dump($data);
die();
When the data is dumped in browser's console, it shows
array(0) {
}
Need help.