Laravel nexmo mobile number verification

 

Controller

<?php

namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Contact;
use Nexmo;
class UserController extends Controller
{
    public function create()
    {
        return view('backend.user.create');
    }
    public function store(Request $req)
    {
        $code=rand(1111,9999);


        $user=new Contact;
        $user->phone=$req->phone;
        $user->code=$code;
        $user->save();

        $nexmo=app('Nexmo\Client');
        $nexmo->message()->send([
            'to'=>'+880'.(int) $req->phone,
            'from'=> 'TS Durjoy',
            'text'=>'Verify code: '.$code,
        ]);

        return redirect('/verify');

    }

    public function GetVerify()
    {
         return view('backend.user.verify');
    }
    public function PostVerify(Request $req)
    {
         $check=Contact::where('code',$req->code)->first();
         if( $check){
             $check->code=Null;
             $check->save();
             return redirect('/');
         }else{
             return back()->withMessage('Verify code is not correct');
         }
    }
}
 

 create.blade.php

 @extends('layouts.app')
@section('content')

<div style="padding-left: 100px;">
    <form action="/user" method="POST">
        {{csrf_field()}}
    <input type="text" name="phone" placeholder="012855...."><br>
    <input type="submit" value="Submit">
    </form>
</div>

@endsection

verify.blade.php 

@extends('layouts.app')
@section('content')

 @if(Session::has('message'))
                    <div class="alert alert-danger">{{Session::get('message')}}</div>
  @endif

<div style="padding-left: 100px;">
    <form action="/verify" method="POST">
        {{csrf_field()}}
    <input type="text" name="code" placeholder="2586"><br>
    <input type="submit" value="Verify">
    </form>
</div>

@endsection


Models

Contact.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Contact extends Model
{
    use HasFactory;
     protected $guarded = [];
}

Route

Route::get('/user','Backend\UserController@create');
Route::post('/user','Backend\UserController@store');
Route::get('/verify','Backend\UserController@GetVerify');
Route::post('/verify','Backend\UserController@PostVerify');



My Website : Basabaribd.com

 

how to send otp on mobile number in laravel

how to send otp to mobile in laravel

mobile number validation in laravel

mobile number validation in laravel 8

mobile number verification in laravel blade

mobile number verification in laravel form

mobile number verification in laravel framework

mobile otp in laravel app

mobile otp in laravel application

mobile otp in laravel blade

mobile otp in laravel controller

mobile otp in laravel datatable

 

No comments

Powered by Blogger.