Skip to content

Instantly share code, notes, and snippets.

@mansha99
Created August 21, 2023 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mansha99/3aaeed37c6d8cb002dcd5c8742a24fa3 to your computer and use it in GitHub Desktop.
Save mansha99/3aaeed37c6d8cb002dcd5c8742a24fa3 to your computer and use it in GitHub Desktop.
Factory Pattern Laravel Client controller
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Requests\MobileVerificationRequest;
use App\Services\SmsService;
class VerificationController extends Controller
{
private $smsService;
public function __construct(SmsService $smsService)
{
$this->smsService = $smsService;
}
public function getVerificationCode(MobileVerificationRequest $request)
{
$data = $request->validated();
$mobile = $data['mobile'];
//Step-1 should be : Check if mobile number is registered with us
//Step-2 should : Check if an SMS has already been sent in last 60 seconds
//Step-3 : if mobile number is registered and no SMS been sent in last 60 seconds
$code = rand(100000, 999999);
//Write logic to Store code in database
//send SMS
$result = $this->smsService->sendSMS($data['mobile'], 'Verification Code for WowApp is ' . $code);
return response()->json($result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment