I'm using Laravel for the backend for an Android app.
I want to update the user picture, but when uploading the file + additional data to my backend, the file is missing in the request:
dd($request->hasFile('avatar')); // false
dd($request->File('avatar')); // null
This is what I sent in Postman (by the way i'm using Passport):
// Headers
Accept: application/json
Authorization: Bearer {{token}}
Content-Type: multipart/form-data
// Body of the request
'avatar' -> the image (in postman)
This is some of my update method, the part that manage the file:
public function update(Request $request)
{
// ...
if($request->hasFile('avatar'))
{
$avatar = $request->file('avatar');
$filename = time() . '.' . $avatar->getClientOriginalExtension();
Image::make($avatar)->resize(300,300)->save('/path/' . $filename));
$user->avatar = $filename;
}
// ...
$user->save();
// ...
}
I don't know what am I doing wrong. Thanks in advance.