PHP code example of aliarefavin / avinauthpackage

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

    

aliarefavin / avinauthpackage example snippets


use AliArefAvin\AvinAuthPackage\Services\AvinAuthService;


$result = (new AvinAuthService())->sendOTP($mobile, $request, $class);
        // Check if the request was successful
        if ($result['success'] && !array_key_exists('seconds', $result)) {
            // If the request was successful and the 'seconds' key is not present in the result,
            // set the 'seconds' key to the configured resend delay time
            $result['seconds'] = config('avinauthconfig.resend_delay');
        }
        // Return the result array, which contains information about the request status
        return $result;

namespace App\Services\Auth;

use AliArefAvin\AvinAuthPackage\Contracts\AvinAuthInterface;

class AuthenticateService implements AvinAuthInterface
{
    public function send(string $receiver, string $code)
    {
        try {
            $Message = 'کد ورود شما:' . PHP_EOL .
                "code: $code" . PHP_EOL ;
                // If the receiver is not in the list of test numbers, send the SMS notification
                Notification::route(NotifyType::TSMS, []) // Set the notification route for SMS
                ->notify(
                    new SendSmsNotification( // Create a new SMS notification
                        $receiver, // The receiver's mobile number
                        $Message // The message content
                    )
                );
            return true; // Return true if the message was sent successfully
        } catch (Exception $e) {
            // If there is an exception (e.g., sending fails), return false
            return false; // Indicate that sending the code failed
        }
    }
}


$request->validate([
    'mobile' => ['bile',
]);
bash
php artisan migrate
bash
php artisan vendor:publish --tag=avinauth-config