Laravel Mobile Verification

Many web applications require users to verify their mobile phone numbers before using the application. Rather than forcing you to re-implement this on each application, ‘Laravel Mobile Verification’ is a package that provides convenient methods and features for send, verify and resend verification codes.
Basic Setup
In the beginning, make sure your User
model implements the MustVerifyMobile
interface and use respected trait:
Next, you should specify your SMS service which any service are applicable. For sending SMS notifications via this package, you need to implement the SMSClient
interface. This interface requires you to implement sendMessage
method and this method will return your SMS service API result via a Payload
object which contains user phone number and token message:
In order to set your SMS Client, you should publish the mobile_verifier.php config file with:
php artisan vendor:publish --provider="Fouladgar\MobileVerification\ServiceProvider" --tag="config"
And set your client class:
Finally, you should run migration command:
php artisan migrate
Usage
Here is how you can send a verification token after user registration:
Verify
You should send token
message of an authenticated user to this route /auth/mobile/verify
:
curl -X POST \
http://example.com/auth/mobile/verify \
-H 'Accept: application/json' \
-H 'Authorization: YOUR_JWT_TOKEN' \
-F token=YOUR_VERIFICATION_TOKEN
Resend
If you need to resend a verification token message, you can use this route /auth/mobile/resend
for an authenticated user:
curl -X POST \
http://example.com/auth/mobile/resend \
-H 'Accept: application/json' \
-H 'Authorization: YOUR_JWT_TOKEN'
For more details, please check out the documentation in GitHub: