Edit File: ProfileController.php
<?php namespace App\Http\Controllers\Api\User; use App\Http\Requests\Api\User\Profile\{VerifyUpdatingPhoneRequest, UpdatePhoneSendCodeRequest, UpdateProfileRequest, UpdateLangRequest}; use App\Services\Auth\ProfileBaseService; use App\Http\Controllers\Controller; use Illuminate\Http\JsonResponse; use App\Traits\ResponseTrait; class ProfileController extends Controller { use ResponseTrait; protected $service; public function __construct(ProfileBaseService $service) { $this->service = $service; } /** * Get the user profile * * @return JsonResponse */ public function getProfile(): JsonResponse { // Get the user profile $data = $this->service->getProfile(); return $this->response($data['key'], $data['msg'], $data['user']); } /** * Update the user profile * * @param UpdateProfileRequest $request * @return JsonResponse */ public function update(UpdateProfileRequest $request) { // Update the user profile $data = $this->service->updateProfile($request->validated()); // Return the success response with the message and user resource return $this->response('success', $data['msg'], $data['user']); } /** * BEGAIN::Second Scenario for updating the phone number */ /** * Send a verification code to the user's old phone number * @param UpdatePhoneSendCodeRequest $request * @return JsonResponse */ public function sendCodeToOldPhone(UpdatePhoneSendCodeRequest $request): JsonResponse { // Send a verification code to the user's old phone number $data = $this->service->sendCodeToOldPhone($request); // Return the response return $this->response($data['key'], $data['msg'], $data['user']); } /** * Verify the user's old phone number * @param VerifyUpdatingPhoneRequest $request * @return JsonResponse */ public function verifyOldPhone(VerifyUpdatingPhoneRequest $request): JsonResponse { // Verify the user's old phone number $data = $this->service->verifyOldPhone($request); // Return the response return $this->response($data['key'], $data['msg'], $data['user']); } /** * Send a verification code to the user's new phone number * @param UpdatePhoneSendCodeRequest $request * @return JsonResponse */ public function sendCodeToNewPhone(UpdatePhoneSendCodeRequest $request): JsonResponse { // Send a verification code to the user's new phone number $data = $this->service->sendCodeToNewPhone($request); // Return the response return $this->response($data['key'], $data['msg'], $data['data']); } /** * Verify the user's new phone number * @param VerifyUpdatingPhoneRequest $request * @return JsonResponse */ public function verifyNewPhone(VerifyUpdatingPhoneRequest $request): JsonResponse { // Verify the user's new phone number $data = $this->service->verifyNewPhone($request); // Return the response return $this->response($data['key'], $data['msg'], $data['user']); } /** * END::Second Scenario for updating the phone number */ /** * Update language * @param UpdateLangRequest $request * @return JsonResponse */ public function updateLanguage(UpdateLangRequest $request): JsonResponse { // Update the user's language $this->service->updateLanguage($request); // Return a success message return $this->successMsg(__('apis.updated')); } }
Back to File Manager