only('email', 'password'))) { return response()->json(['error' => 'invalid_credentials'], 401); } } catch (JWTException $e) { Log:error($e); return response()->json(['error' => 'could_not_create_token'], 500); } return response()->json(compact('token')); } /** * Log the current user out. * * @return \Illuminate\Http\JsonResponse */ public function logout() { try { JWTAuth::invalidate(JWTAuth::getToken()); } catch (JWTException $e) { Log:error($e); return response()->json(['error' => 'could_not_invalidate_token'], 500); } return response()->json(); } /** * Create a new user. * * @param UserStoreRequest $request * * @return \Illuminate\Http\JsonResponse */ public function store(UserStoreRequest $request) { return response()->json(User::create([ 'name' => $request->input('name'), 'email' => $request->input('email'), 'password' => Hash::make($request->input('password')), ])); } /** * Update a user. * * @param UserUpdateRequest $request * @param User $user * * @return \Illuminate\Http\JsonResponse */ public function update(UserUpdateRequest $request, User $user) { $data = $request->only('name', 'email'); if ($password = $request->input('password')) { $data['password'] = Hash::make($password); } return response()->json($user->update($data)); } /** * Delete a user. * * @param User $user * * @return \Illuminate\Http\JsonResponse */ public function destroy(User $user) { $this->authorize($user); return response()->json($user->delete()); } /** * Update the current user's profile. * * @param ProfileUpdateRequest $request * * @return \Illuminate\Http\JsonResponse */ public function updateProfile(ProfileUpdateRequest $request) { $data = $request->only('name', 'email'); if ($password = $request->input('password')) { $data['password'] = Hash::make($password); } return response()->json(auth()->user()->update($data)); } }