PHP code example of alhaji-aki / laravel-phone-number-verification

1. Go to this page and download the library: Download alhaji-aki/laravel-phone-number-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/ */

    

alhaji-aki / laravel-phone-number-verification example snippets




namespace App\Models;

use AlhajiAki\OtpToken\Contracts\CanSendOtpToken as CanSendOtpTokenContract;
use AlhajiAki\OtpToken\Traits\CanSendOtpToken;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable implements CanSendOtpTokenContract
{
    use Notifiable, CanSendOtpToken;
}



namespace App\Models;

use AlhajiAki\OtpToken\Contracts\CanSendOtpToken as CanSendOtpTokenContract;
use AlhajiAki\OtpToken\Traits\CanSendOtpToken;
use AlhajiAki\PhoneNumberVerification\Contracts\MustVerifyPhoneNumber as MustVerifyPhoneNumberContract;
use AlhajiAki\PhoneNumberVerification\Traits\MustVerifyPhoneNumber;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable implements CanSendOtpTokenContract, MustVerifyPhoneNumberContract
{
    use Notifiable, CanSendOtpToken, MustVerifyPhoneNumber;
}



namespace App\Models;

use AlhajiAki\OtpToken\Contracts\CanSendOtpToken as CanSendOtpTokenContract;
use AlhajiAki\OtpToken\Traits\CanSendOtpToken;
use AlhajiAki\PhoneNumberVerification\Contracts\MustVerifyPhoneNumber as MustVerifyPhoneNumberContract;
use AlhajiAki\PhoneNumberVerification\Traits\MustVerifyPhoneNumber;
use App\Notifications\Auth\VerifyPhoneNumber;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable implements CanSendOtpTokenContract, MustVerifyPhoneNumberContract
{
    use Notifiable, CanSendOtpToken, MustVerifyPhoneNumber;

    public function phoneNumberAttribute(): string
    {
        return 'phone_number';
    }

    public function phoneNumberVerificationAttribute(): string
    {
        return 'phone_number_verified_at';
    }

    public function sendPhoneNumberVerificationNotification(string $token): void
    {
        $this->notify(new VerifyPhoneNumber($token));
    }
}

/**
 * The event listener mappings for the application.
 *
 * @var array<class-string, array<int, class-string>>
 */
protected $listen = [
    ...
    Registered::class => [
        SendPhoneNumberVerificationNotification::class,
    ],
    ...
];

protected $routeMiddleware = [
    ...
    'mobile-verified' => \AlhajiAki\PhoneNumberVerification\Middleware\EnsurePhoneNumberIsVerified::class,
    ...
];
bash
php artisan phone-number-verification:install
bash
php artisan vendor:publish --provider="AlhajiAki\OtpToken\OtpTokenServiceProvider"
bash
php artisan migrate
bash
composer analyse