Many web applications require users to verify their mobile 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 forsend,verify andresend verification codes.
Basic Setup
In the beginning, verify that yourUser
model implements theMustVerifyMobile
interface and use respected trait:
Next, you should specify your SMS service which any service (i.e.Nexmo
,Twilio
) are applicable. For sending SMS notifications via this package, you need to implement theSMSClient
interface. This interface requires you to implementsendMessage
method and this method will return your SMS service API result via aPayload
object which contains usermobile number andtoken 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:
Usage
Here is how you can send a verification token after user registration:
Verify
You should sendtoken
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'\-Ftoken=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:
mohammad-fouladgar / laravel-mobile-verification
This package provides convenient methods for sending and verifying mobile verification requests.
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse