2016-05-30 05:50:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
|
|
|
|
use App\Http\Requests\API\ProfileUpdateRequest;
|
2018-08-22 19:46:36 +00:00
|
|
|
use Illuminate\Contracts\Hashing\Hasher as Hash;
|
2017-06-04 01:30:45 +00:00
|
|
|
use Illuminate\Http\JsonResponse;
|
2017-08-27 15:53:17 +00:00
|
|
|
use Illuminate\Http\Request;
|
2017-06-04 01:30:45 +00:00
|
|
|
use RuntimeException;
|
2016-05-30 05:50:59 +00:00
|
|
|
|
|
|
|
class ProfileController extends Controller
|
|
|
|
{
|
2018-08-22 19:46:36 +00:00
|
|
|
private $hash;
|
|
|
|
|
|
|
|
public function __construct(Hash $hash)
|
|
|
|
{
|
|
|
|
$this->hash = $hash;
|
|
|
|
}
|
|
|
|
|
2017-08-27 15:53:17 +00:00
|
|
|
/**
|
|
|
|
* Get the current user's profile.
|
|
|
|
*
|
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
|
|
|
public function show(Request $request)
|
|
|
|
{
|
|
|
|
return response()->json($request->user());
|
|
|
|
}
|
|
|
|
|
2016-05-30 05:50:59 +00:00
|
|
|
/**
|
|
|
|
* Update the current user's profile.
|
|
|
|
*
|
2017-06-04 01:30:45 +00:00
|
|
|
* @throws RuntimeException
|
2016-08-03 10:42:39 +00:00
|
|
|
*
|
2017-06-04 01:30:45 +00:00
|
|
|
* @return JsonResponse
|
2016-05-30 05:50:59 +00:00
|
|
|
*/
|
|
|
|
public function update(ProfileUpdateRequest $request)
|
|
|
|
{
|
|
|
|
$data = $request->only('name', 'email');
|
|
|
|
|
2017-04-29 02:55:41 +00:00
|
|
|
if ($request->password) {
|
2018-08-22 19:46:36 +00:00
|
|
|
$data['password'] = $this->hash->make($request->password);
|
2016-05-30 05:50:59 +00:00
|
|
|
}
|
|
|
|
|
2017-05-02 03:23:10 +00:00
|
|
|
return response()->json($request->user()->update($data));
|
2016-05-30 05:50:59 +00:00
|
|
|
}
|
|
|
|
}
|