Nowadays, there is a lot of application moving from traditional email/password to phone number/password as the main authentication. It is because the OTP method we could say it much more secure than email verification. Hence, the phone number has been the one of authentication ID to access sensitive information. In such situations, it’s vital for the system to verify that the phone numbers are valid and functional.
Goto:
https://github.com/craftsys/msg91-laravel
composer require craftsys/msg91-laravel
config/app.php 'providers' => [ // Other service providers... Craftsys\Msg91\Msg91LaravelServiceProvider::class, ], 'aliases' => [ // other aliases here 'Msg91' => Craftsys\Msg91\Facade\Msg91::class, ],
config/services.php "msg91" => [ 'key' => env("Msg91_KEY"), ],
php artisan make:controller SMSController
SMSController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Craftsys\Msg91\Facade\Msg91; // add this line of code
class SMSController extends Controller
{
//
}
Some Important functions // send otp Msg91::otp()->to(919999999999)->send(); // resend otp Msg91::otp()->to(919999999999)->viaVoice()->resend(); // verify otp Msg91::otp(678612)->to(919999999999)->verify(); // send sms Msg91::sms()->to(919999999999)->flow('<flow_id>')->send(); // in bulk Msg91::sms()->to([919999999999, 918899898990])->flow('<flow_id>')->send(); // with variables in your flow template Msg91::sms()->to([919999999999, 918899898990])->flow('<flow_id>')->variable('variable_name', 'value')->send(); // with variables per recipient Msg91::sms()->recipients([ ['mobiles' => 919999999999, 'name' => 'Sudhir M'], ['mobiles' => 918899898990, 'name' => 'Craft Sys'] ]) ->flow('<flow_id>') ->send();
Send otp Msg91::otp() ->to(912343434312) // phone number with country code ->template('your_template_id') // set the otp template ->send(); // send the otp
Verify otp Msg91::otp(1234) // OTP to be verified ->to(912343434312) // phone number with country code ->verify(); // Verify
Resend otp Msg91::otp() ->to(912343434312) // set the mobile with country code ->viaVoice() // set the otp sending method (can be "viaText" as well) ->resend(); // resend otp
Sendings sms Msg91::sms() ->to(912343434312) // set the mobile with country code ->flow("your_flow_id_here") // set the flow id ->send(); // send
Bulk sms Msg91::sms() ->to([912343434312, 919898889892]) // set the mobiles with country code ->flow("your_flow_id_here") // set the flow id ->send(); // send
.env
Msg91_KEY = '340546AOZLLkijdUd606af89dP1' (auth key)
composer dump-autoload
config/services.php
"msg91" => [
'key' => env("Msg91_KEY"),
],
SMSController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Craftsys\Msg91\Facade\Msg91; // add this line of code
class SMSController extends Controller
{
function sendmsg(Request $req){
Msg91::sms()
->to([918085289889]) // set the mobiles with country code
->flow("your_flow_id_here") // set the flow id
->send(); // send
}
}