Laravel 10 Firebase Phone Number OTP Auth Example

Laravel 10 phone or mobile number OTP verification using firebase. In this tutorial, you will learn how to use firebase otp authentication for mobile or phone in Laravel 10 app.

first of all, you need to visit Firebase Console and create a project. then you have to create web app on that project as like below screenshot:

After given name and next then you will received firebase sdk as like bellow screen shot:

Next you need to enable phone number auth from bellow link:

You have to save that all information because we will use in our app.

Laravel 10 Firebase Phone Number OTP Authentication Tutorial

  • Step 1 – Download Laravel 10 Application
  • Step 2 – Connecting App to Database
  • Step 3 – Create View
  • Step 4 – Create Route
  • Step 5 – Create Controller By Artisan Command
  • Step 6 – Run Development Server

Step 1 – Download Laravel 10 Application

First of all, start your terminal to download or install Laravel 10 new setup. Execute the following command into it to install new Laravel 10 app into your system:

composer create-project --prefer-dist laravel/laravel blog

Step 2 – Connecting App to Database

In this step, Configure your database with your apps. So, visit your app root directory and find .env file. Then configure database details as follows:


Step 3 – Create View

In this step, visit resources/views directory and create one blade view file named index.blade.php. And then add the following code into it:

<title>Laravel 10 Phone Number Authentication using Firebase -</title>
<!-- CSS only -->
<link href="[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src=""></script>
<div class="container">
<h1>Laravel 10 Phone Number Authentication using Firebase -</h1>
<div class="alert alert-danger" id="error" style="display: none;"></div>
<div class="card">
<div class="card-header">
Enter Phone Number
<div class="card-body">
<div class="alert alert-success" id="sentSuccess" style="display: none;"></div>
<label>Phone Number:</label>
<input type="text" id="number" class="form-control" placeholder="+91********">
<div id="recaptcha-container"></div>
<button type="button" class="btn btn-success" onclick="phoneSendAuth();">SendCode</button>
<div class="card" style="margin-top: 10px">
<div class="card-header">
Enter Verification code
<div class="card-body">
<div class="alert alert-success" id="successRegsiter" style="display: none;"></div>
<input type="text" id="verificationCode" class="form-control" placeholder="Enter verification code">
<button type="button" class="btn btn-success" onclick="codeverify();">Verify code</button>
<script src=""></script>
var firebaseConfig = {
apiKey: "AIzaSyBPdVwUIYOY0qRr9kbIMTnxKpFw_nkneYk",
authDomain: "",
databaseURL: "",
projectId: "itdemo-push-notification",
storageBucket: "",
messagingSenderId: "257055232313",
appId: "1:257055232313:web:3f09127acdda7298dfd8e8",
measurementId: "G-VMJ68DFLXL"
<script type="text/javascript">
window.onload=function () {
function render() {
window.recaptchaVerifier=new firebase.auth.RecaptchaVerifier('recaptcha-container');
function phoneSendAuth() {
var number = $("#number").val();
firebase.auth().signInWithPhoneNumber(number,window.recaptchaVerifier).then(function (confirmationResult) {
$("#sentSuccess").text("Message Sent Successfully.");
}).catch(function (error) {
function codeverify() {
var code = $("#verificationCode").val();
coderesult.confirm(code).then(function (result) {
var user=result.user;
$("#successRegsiter").text("you are register Successfully.");
}).catch(function (error) {

Step 4 – Create Routes

In this step, Visit your routes directory and open web.php file in any text editor. And add the following routes into web.php route file:

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\FirebaseController;
| Web Routes
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
Route::get('firebase-phone-authentication', [FirebaseController::class, 'index']);

Step 5 – Create Controller By Artisan Command

In this step, execute the following command on terminal/command prompt/command line to create controller file for your laravel applications; is as follow:

php artisan make:controller FirebaseController

Now, visit your laravel directory app/http/controllers and open FirebaseController.php file. And update the following code into it:

namespace App\Http\Controllers;
use Illuminate\Http\Request;
class FirebaseController extends Controller
* Write code on Method
* @return response()
public function index()
return view('index');

Step 6 – Run Development Server

Finally, open command prompt and run the following command to start developement server:

php artisan serve

Then open your browser and hit the following url on it:

Recommended Laravel Posts

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Jassweb, Rai Chak, Punjab, India. 143518