Hello all,
I'm experiencing a problem with my Laravel API, actually, I'm not sure if the problem is in my Laravel API or my frontend App (if so, sorry for bothering in this forum). The situation is this.
I'm trying to upload a single file from the frontend into the laravel API. For this, I'm using AngularJS and ng-file-upload.
From postman, I'm using these settings (http://i.stack.imgur.com/o9LHM.jpg) :
- Method: Post
- URL: api/account/1?&_method=PUT
- Params:
- Body:
- name: Test
- logo: A selected file from my computer
Using these settings, Postman is uploading the file successfully. In my Laravel controller, I have this:
public function update(Account $account)
{
$name = Input::get('name');
$logo = Input::file('logo');
$account->name = $name;
$account->logo = $logo;
$account->save();
return response()->json(["message"=>"updated"]);
}
But from my AngularJS, it appears like I'm using the same approach but my Laravel API looks like is not receiving nothing!
This is my relevant code about the Laravel API call on AngularJS.
Upload.upload({
url: 'api/account/'+ $scope.id,
method: 'PUT',
file: logo,
sendFieldsAs: 'form-data',
fields: { name: $scope.name },
})
If anyone has a clue, please let me know. I think the problem is with the PUT method, but I'm not sure.
I have been dealing with this problem by some hours ago.
BTW, I already used another way to upload a file from Angular, and the result is the same. That's the reason that I decided to open this thread, because probably is the way I'm obtaining the data from my Laravel controller.
Thanks in advance.