1. Go to this page and download the library: Download jefte/otpgenerator 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/ */
jefte / otpgenerator example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Jefte\OTPGenerator\Traits\HasOTPToken;
class User extends Authenticatable
{
use HasFactory, Notifiable, HasOTPToken;
}
class HomeController extends Controller
{
public function requestOtpToken(Request $request)
{
$user = $request->user();
// Creating Token
$token = $user->createOtpToken();
// Accessing the created token
$token->getGeneratedToken();
// Sample Use Case
$user->notify(new SendOtpNotification($token));
}
public function verifyOtpToken(Request $request)
{
$user = $request->user();
// To Verify Token
$token = $request->input('otp_token');
if(! $user->verifyToken($myToken))
{
return response()->json([
'message' => 'Invalid OTP'
], 422);
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.