1
0
mirror of https://github.com/flarum/core.git synced 2025-08-04 23:47:32 +02:00

Refresh avatar display after uploading

This commit is contained in:
Toby Zerner
2015-03-27 11:49:26 +10:30
parent 38bbfc78d0
commit 257a3fde1a
5 changed files with 36 additions and 9 deletions

View File

@@ -2,6 +2,7 @@
use Flarum\Api\Actions\BaseAction;
use Flarum\Core\Commands\UploadAvatarCommand;
use Flarum\Api\Serializers\UserSerializer;
use Illuminate\Http\Request;
class UploadAvatarAction extends BaseAction
@@ -11,11 +12,14 @@ class UploadAvatarAction extends BaseAction
$userId = array_get($routeParams, 'id');
$file = $request->file('avatar');
$this->dispatch(
$user = $this->dispatch(
new UploadAvatarCommand($userId, $file, $this->actor->getUser()),
$routeParams
);
return $this->respondWithoutContent(201);
$serializer = new UserSerializer;
$document = $this->document()->setData($serializer->resource($user));
return $this->respondWithDocument($document);
}
}

View File

@@ -226,6 +226,16 @@ class User extends Model
return $this;
}
/**
* Get the URL of the user's avatar.
*
* @return string
*/
public function getAvatarUrlAttribute()
{
return $this->avatar_path ? asset('avatars/'.$this->avatar_path) : null;
}
/**
* Check if a given password matches the user's password.
*