dragg's avatar
Level 13

Validation's fails by upload file with data to Laravel 5.2

Hey everybody, thank you in advance for your help... I have a pretty weird situation.. I have a problem with uploading basic form which is mixed with text inputs and one input file (xls).

I'm using the latest version of Laravel 5.2 and AngularJS plugin ng-file-upload ( https://github.com/danialfarid/ng-file-upload ) for sending and uploading form's request including text fields and one file field (the form is multipart/form-data OR application/x-www-form-urlencoded). The problem is that I'm always getting validation's errors (the fields are required but do not exist). Please see the following code examples, links:

https://postimg.org/image/ezsol70bl/

https://postimg.org/image/qq6m2kt41/

https://postimg.org/image/xuofbm0dd/

We are working with 2 platforms: API and Admin panel SO we have this code in front-end side:

----------- START CODE ----------

(function () {

 'use strict';

  angular

  .module('app')

  .config(['$httpProvider', function ($httpProvider) {

    $httpProvider.defaults.useXDomain = true;

    $httpProvider.defaults.withCredentials = false;

    delete $httpProvider.defaults.headers.common["X-Requested-With"];

    $httpProvider.defaults.headers.common["Accept"] = "application/json";

    $httpProvider.defaults.headers.common["Content-Type"] = "application/json";



    $httpProvider.interceptors.push('HttpInterceptor');

  }

  ]);

})();

----------- END CODE ------------

Any advice to reveal what is the right way to upload a file with the "form fields" (type="file" and "text" inputs) on the same time? Thank you.

0 likes
1 reply
dragg's avatar
dragg
OP
Best Answer
Level 13

I found the cause of my issue - I used PUT method for uploading the file, but Laravel doesn't support it.

1 like

Please or to participate in this conversation.