PHP code example of envoisms / laravel-otp

1. Go to this page and download the library: Download envoisms/laravel-otp 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/ */

    

envoisms / laravel-otp example snippets


'envoisms' => [
    'api_key' => env('ENVOISMS_API_KEY'),
    'from' => env('ENVOISMS_FROM', 'EnvoiSMS'),
],

namespace App\Notifications;

use EnvoiSMS\Laravel\EnvoiSMSChannel;
use EnvoiSMS\Laravel\Messages\EnvoiSMSMessage;
use Illuminate\Notifications\Notification;

class SendOtpNotification extends Notification
{
    public function via($notifiable): array
    {
        return [EnvoiSMSChannel::class];
    }

    public function toEnvoiSMS($notifiable): EnvoiSMSMessage
    {
        return (new EnvoiSMSMessage())
            ->asOtp(brand: 'MonApp', codeLength: 6, expiry: 600);
    }
}

$user->notify(new SendOtpNotification());

public function toEnvoiSMS($notifiable): EnvoiSMSMessage
{
    return (new EnvoiSMSMessage())
        ->content("Bonjour {$notifiable->first_name}, votre commande #{$this->order->id} est expédiée.")
        ->from('MonBusiness'); // validated Sender ID, or omit for the account default
}

use EnvoiSMS\Laravel\Facades\EnvoiSMS;

// Send OTP
$response = EnvoiSMS::sendOtp([
    'to' => '+212600000000',
    'brand' => 'MonApp',
]);

// Check OTP Code
$result = EnvoiSMS::checkOtp(
    sessionId: $response['session_id'],
    code: '123456'
);

if ($result['verified']) {
    // Code valid
}