Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Laravel Mobile Verification
Fouladgar.dev
Fouladgar.dev

Posted on • Edited on

     

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 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:

GitHub logo mohammad-fouladgar / laravel-mobile-verification

This package provides convenient methods for sending and verifying mobile verification requests.

Laravel Mobile Verification

alt text

Build StatusCoverage StatusQuality ScoreLatest Stable VersionTotal DownloadsLicense

Introduction

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, this package provides convenient methods for sending and verifying mobile verification requests.

Installation

You can install the package via composer:

composer require fouladgar/laravel-mobile-verification

Laravel 5.5 uses Package Auto-Discovery, so you are not required to add ServiceProvider manually.

Laravel <= 5.4.x

If you don't use Auto-Discovery, add the ServiceProvider to the providers array inconfig/app.php file

'providers'=> [/*   * Package Service Providers...*/Fouladgar\MobileVerification\ServiceProvider::class,],

Configuration

To get started, you should publish theconfig/mobile_verification.php config file with:

php artisan vendor:publish --provider="Fouladgar\MobileVerification\ServiceProvider" --tag="config"

If you’re using another table name forusers table or different column name formobile or evenmobile_verification_tokens table, you can customize their values in config file:

// config/mobile_verification.php<?phpreturn

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Software Designer
  • Work
    Senior Back-End Developer
  • Joined

More fromFouladgar.dev

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp