0

I am new to laravel and angularjs. I want to integrate angularjs with laravel. I want to make register form with fields like name,email,password, profile image. I want to submit that form using angularjs to laravel controller to store data in db. i am using below code to pass form data to controller.

$http({
        method: 'POST',
        url: url,
        data: $scope.employees,
        headers: {'Content-Type': undefined}
    }).success(function (response) {
        console.log(response);
    }).error(function (response) {
        console.log(response);
        alert('This is embarassing. An error has occured. Please check the log for details');
    });

can anybody guide me how can i get all the data from form including image file and other fields. I have also try to pass form data using FormData() but in that case i only get image file.

Adarsh Bhatt
  • 548
  • 1
  • 9
  • 30

1 Answers1

0

The best solution would be for you to encode your data as json and then retrieve it on the server side and decode it. Also make sure the request has the json content type.

Raress96
  • 214
  • 3
  • 7
  • can i pass image into json string? – Adarsh Bhatt Jun 15 '18 at 10:48
  • Yes, but it is a little bit more complicated, you will have to encode it as base64 image and then decode it on the server. Another approach would be to use FormData and add all the information to it. These might help you: https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects https://stackoverflow.com/a/8244082/8257958 And I believe the Content-Type should be multipart/form-data – Raress96 Jun 15 '18 at 11:09
  • is there any other way to make this working with angularjs and laravel? – Adarsh Bhatt Jun 16 '18 at 05:51