mirror of
https://github.com/koel/koel
synced 2024-12-21 01:53:11 +00:00
47 lines
1,011 B
PHP
47 lines
1,011 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
use App\Http\Requests\API\ProfileUpdateRequest;
|
|
use Illuminate\Contracts\Hashing\Hasher as Hash;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use RuntimeException;
|
|
|
|
class ProfileController extends Controller
|
|
{
|
|
private $hash;
|
|
|
|
public function __construct(Hash $hash)
|
|
{
|
|
$this->hash = $hash;
|
|
}
|
|
|
|
/**
|
|
* Get the current user's profile.
|
|
*
|
|
* @return JsonResponse
|
|
*/
|
|
public function show(Request $request)
|
|
{
|
|
return response()->json($request->user());
|
|
}
|
|
|
|
/**
|
|
* Update the current user's profile.
|
|
*
|
|
* @throws RuntimeException
|
|
*
|
|
* @return JsonResponse
|
|
*/
|
|
public function update(ProfileUpdateRequest $request)
|
|
{
|
|
$data = $request->only('name', 'email');
|
|
|
|
if ($request->password) {
|
|
$data['password'] = $this->hash->make($request->password);
|
|
}
|
|
|
|
return response()->json($request->user()->update($data));
|
|
}
|
|
}
|