mardi 1 août 2017

Response is returning blank

im working in an app that has his frontend on angularjs and uses laravel 5 as backend. Im trying to upload files, but in the console, the response is a blank space.

This is my controller in angular that handle the files

    vm.makeFile = function(newFile){
        vm.shipmentObject.files=[];
        vm.newDateFile= new Date();
        vm.newDateFile = $filter('date')(vm.newDateFile, "yyyy-MM-dd h:mm:ss");
        vm.shipmentObject.files.push({
            "id":23,
            "shipment_id":43,
            "user_id":20,
            "date":vm.newDateFile,
            "file": "vm.shipmentObject.file",
            "fileName":"aguacate",
            "fileType":"jpg",
            "status":"I"
        });

        ShipmentResource.insertFile({files:vm.shipmentObject.files}).success(function(response){
            console.log(response);
            console.log("FILE INSERTED CORRECTLY");
        });

            console.log(vm.shipmentObject.files);
    };

And this is my controller in laravel that handles the files

 public function makeFile(Request $request)
    {
        if(isset($request->files) && is_array($request->files)){
            $fileArray=[];
            foreach($request->files as $key=>$fileEntity){
                $file= new File();
                $file->file=$fileEntity['file'];
                $file->shipment_id=$fileEntity['shipment_id'];
                $file->user_id=$fileEntity['user_id'];
                $file->date=date('Y,m,d,G,i,s');
                $file->fileName=$fileEntity['fileName'];
                $file->fileType=$fileEntity['fileType'];
                $file->status=$fileEntity['status'];
                $file->save();

                array_push($fileArray, $file);
            }

        }
  return response()->json();
    }

In that way, the console logs are printing in the browser this:

enter image description here

A BLANK RESPONSE, At the end of the laravel controller if i change this

return response()->json()

for this

return response()->json($fileArray)

The response is a 500 error

ErrorException in ShipmentController.php line 132: Undefined variable: fileArray in ShipmentController.php line 132 at HandleExceptions->handleError('8', 'Undefined variable: fileArray', 'C:\xampp\htdocs\zignyWS\app\Http\Controllers\ShipmentController.php', '132', array('request' => object(Request))) in ShipmentController.php line 132

the line 132 is this one -> return response()->json($fileArray)

I dont know where the problem is, it may be because of the way that are sending the request? enter image description here

I think the problem its in the backend side...

im stuck in this, after that i need to display the file in the app if its a pdf and add validations only to upload xls,pdf and doc files., but please help me with this blank response issue first



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire