mirror of
https://github.com/flarum/framework.git
synced 2024-11-24 08:54:21 +08:00
Add route and action for uploading user avatars.
This commit is contained in:
parent
a1f723671d
commit
100a5038bf
21
src/Api/Actions/Users/UploadAvatarAction.php
Normal file
21
src/Api/Actions/Users/UploadAvatarAction.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php namespace Flarum\Api\Actions\Users;
|
||||
|
||||
use Flarum\Api\Actions\BaseAction;
|
||||
use Flarum\Core\Commands\UploadAvatarCommand;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UploadAvatarAction extends BaseAction
|
||||
{
|
||||
public function handle(Request $request, $routeParams = [])
|
||||
{
|
||||
$userId = array_get($routeParams, 'id');
|
||||
$file = $request->file('avatar');
|
||||
|
||||
$this->dispatch(
|
||||
new UploadAvatarCommand($userId, $this->actor->getUser(), $file),
|
||||
$routeParams
|
||||
);
|
||||
|
||||
return $this->respondWithoutContent(201);
|
||||
}
|
||||
}
|
|
@ -59,6 +59,11 @@ Route::group(['prefix' => 'api', 'middleware' => 'Flarum\Api\Middleware\LoginWit
|
|||
'uses' => $action('Flarum\Api\Actions\Users\DeleteAction')
|
||||
]);
|
||||
|
||||
Route::post('users/{id}/avatar', [
|
||||
'as' => 'flarum.api.users.avatar.upload',
|
||||
'uses' => $action('Flarum\Api\Actions\Users\UploadAvatarAction')
|
||||
]);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Activity
|
||||
|
|
Loading…
Reference in New Issue
Block a user