PHP code example of fouladgar / laravel-mobile-verification

1. Go to this page and download the library: Download fouladgar/laravel-mobile-verification library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fouladgar / laravel-mobile-verification example snippets


// config/mobile_verifier.php



return [
    /**
    |Supported drivers: "cache", "database"
    */
    'token_storage' => 'cache',
];

// config/mobile_verifier.php



return [

    'user_table'    => 'users',

    'mobile_column' => 'mobile',

    'token_table'   => 'mobile_verification_tokens',

    //...
];



namespace App;

use Fouladgar\MobileVerification\Contracts\MustVerifyMobile as IMustVerifyMobile;
use Fouladgar\MobileVerification\Concerns\MustVerifyMobile;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable implements IMustVerifyMobile
{
    use Notifiable, MustVerifyMobile;

    // ...
}



namespace App;

use Fouladgar\MobileVerification\Contracts\SMSClient;
use Fouladgar\MobileVerification\Notifications\Messages\Payload;

class SampleSMSClient implements SMSClient
{
    protected $SMSService;

    /**
     * @param Payload $payload
     *
     * @return mixed
     */
    public function sendMessage(Payload $payload):mixed
    {
        // preparing SMSService ...

        return $this->SMSService
                 ->send($payload->getTo(), $payload->getToken());
    }

    // ...
}

// config/mobile_verifier.php



return [

  'sms_client' => App\SampleSMSClient::class,

  //...
];



use Illuminate\Auth\Events\Registered;

// Register user

 event(new Registered($user));

//...

// config/mobile_verifier.php



return [

    'middleware' => ['auth:sanctum'],

    //...
];

// config/mobile_verifier.php



return [

    'routes_prefix' => 'auth',

    'routes' => [
        'verify' => '/mobile/verify',
        'resend' => '/mobile/resend',
    ],

    //...
];

// config/mobile_verifier.php



return [

    'controller_namespace' => 'App\Http\Controllers',

    //...
];



namespace App\Http\Controllers;

use Fouladgar\MobileVerification\Http\Controllers\BaseVerificationController;

class MobileVerificationController extends BaseVerificationController
{
    /**
     * Where to redirect users after verification.
     *
     * @var string
     */
    protected $redirectTo = '/home';
}


Route::get('profile', function () {
    // Only verified users may enter...
})->middleware('mobile.verified');

// config/mobile_verifier.php


return [
     /**
     | Supported drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null"
     */
    'queue' =>  [
       'connection' => 'sync',
       'queue' => 'default',
       'tries' => 3,
       'timeout' => 60,
    ]
];

// lang/vendor/MobileVerification/en/mobile_verification.php



return [
    'successful_verification' => 'Your mobile has been verified successfully.',
    'successful_resend'       => 'The token has been resent successfully.',
    'already_verified'        => 'Your mobile already has been verified.',
    //etc...
];

/**
 * The event listener mappings for the application.
 *
 * @var array
 */
protected $listen = [
    'Fouladgar\MobileVerification\Events\Verified' => [
        'App\Listeners\LogVerifiedUser',
    ],
];

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

php artisan migrate

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