Laravel Mobile Verification

Image for post
Image for post
Laravel Mobile Verification

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 for send, verify and resend verification codes.

Basic Setup

In the beginning, verify that your User model implements the MustVerifyMobile 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 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:

And set your client class:

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:

Resend

If you need to resend a verification token message, you can use this route /auth/mobile/resend for an authenticated user:

For more details, please check out the documentation in GitHub:

Software Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store