i'm using Laravel for the backend for an Android app.
I'm trying to update the avatar for the user X (is set to a default.jpg when users are created). But the $request->File('avatar')
is null ($request->hasFile('avatar')
is false
).
This is what I sent in Postman (by the way i'm using Passport):
// Headers
Accept: application/json
Authorization: Bearer
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)
{
// some code
if($request->hasFile('avatar')) {
$avatar = $request->file('avatar');
$filename = time() . '.' . $avatar->getClientOriginalExtension();
Image::make($avatar)->resize(300,300)->save( public_path('/uploads/avatars/' . $filename ) );
$user->avatar = $filename;
}
// code
$user->save();
return something;
I don't know what am I doing wrong. Thanks in advance.
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2sVkIYS
via IFTTT
Aucun commentaire:
Enregistrer un commentaire