koel/app/Http/Controllers/API/ProfileController.php

45 lines
948 B
PHP
Raw Normal View History

2016-05-30 05:50:59 +00:00
<?php
namespace App\Http\Controllers\API;
use App\Http\Requests\API\ProfileUpdateRequest;
use Hash;
2017-06-04 01:30:45 +00:00
use Illuminate\Http\JsonResponse;
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
{
/**
* Get the current user's profile.
*
* @param Request $request
2017-08-27 15:53:50 +00:00
*
* @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.
*
* @param ProfileUpdateRequest $request
*
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) {
$data['password'] = 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
}
}