Laravel 10 CRUD Operation using Google Firebase

Hello developers! Today, I'm thrilled to guide you through the process of implementing CRUD (Create, Read, Update, Delete) operations in Laravel 10 using the power of Google Firebase. Laravel's elegance combined with Firebase's real-time database capabilities provides a robust foundation for building dynamic and responsive applications.

In this step-by-step guide, we'll explore how to seamlessly integrate Firebase into a Laravel 10 project for efficient CRUD operations.

In this article, we'll learn about creating CRUD operations using Firebase in Laravel 8, Laravel 9, and Laravel 10.

Step-by-Step Guide: Laravel 10 CRUD Operations with Google Firebase

Step 1: Set Up a New Laravel 10 Project

Ensure you have Laravel 10 installed. If not, create a new Laravel project using the following commands:

composer create-project laravel/laravel your-project-name
cd your-project-name


Step 2: Configure Firebase Credentials

Create a Firebase project on the Firebase Console, and download the service account key JSON file. Place this file in your Laravel project's config directory.

Step 1:


Enter a project name and check the checkbox and then click on the continue button.

Step 2:


Then click on the continue button.

Step 3:

then click on the web for web development.



Step 3: Add Route

Now, we'll add the route to the web.php file.




Step 4: Configure Firebase Settings

Now, let's configure Google Firebase settings in our Laravel application. Open the services.php file and set the following configuration within this file.


'firebase' => [
    'api_key' => 'api_key',
    'auth_domain' => 'auth_domain',
    'database_url' => 'database_url',
    'project_id' => 'project_id',
    'storage_bucket' => 'storage_bucket',
    'messaging_sender_id' => 'messaging_sender_id',
    'app_id' => 'app_id',
    'measurement_id' => 'measurement_id',


Step 5: Set Up Controller

Create a controller for handling CRUD operations:



namespace App\Http\Controllers;

use Illuminate\Http\Request;

class UserController extends Controller
    public function index()
        return view('users');

Step 6: Create View File

Create Blade views for displaying and managing your data. Use forms to handle create and update operations.


<!doctype html>
<html lang="en">
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Laravel 10 CRUD Operation using Google Firebase - Techsolutionstuff</title>
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="">
    <script src="" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
    <div class="container" style="margin-top: 50px;">
        <h4 class="text-center">Laravel 10 CRUD Operation using Google Firebase - Techsolutionstuff</h4><br>
        <h5># Add User</h5>
        <div class="card card-default">
            <div class="card-body">
                <form id="addUser" class="form-inline" method="POST" action="">
                    <div class="form-group mb-2">
                        <label for="name" class="sr-only">Name</label>
                        <input id="name" type="text" class="form-control" name="name" placeholder="Name"
                               required autofocus>
                    <div class="form-group mx-sm-3 mb-2">
                        <label for="email" class="sr-only">Email</label>
                        <input id="email" type="email" class="form-control" name="email" placeholder="Email"
                               required autofocus>
                    <button id="submitUser" type="button" class="btn btn-primary mb-2">Submit</button>
        <h5># Users</h5>
        <table class="table table-bordered">
                <th width="180" class="text-center">Action</th>
            <tbody id="tbody">

    <!-- Update Model -->
    <form action="" method="POST" class="users-update-record-model form-horizontal">
        <div id="update-modal" data-backdrop="static" data-keyboard="false" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="custom-width-modalLabel"
            <div class="modal-dialog modal-dialog-centered" style="width:55%;">
                <div class="modal-content" style="overflow: hidden;">
                    <div class="modal-header">
                        <h4 class="modal-title" id="custom-width-modalLabel">Update</h4>
                        <button type="button" class="close" data-dismiss="modal"
                    <div class="modal-body" id="updateBody">

                    <div class="modal-footer">
                        <button type="button" class="btn btn-light"
                        <button type="button" class="btn btn-success updateUser">Update

    <!-- Delete Model -->
    <form action="" method="POST" class="users-remove-record-model">
        <div id="remove-modal" data-backdrop="static" data-keyboard="false" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="custom-width-modalLabel"
             aria-hidden="true" style="display: none;">
            <div class="modal-dialog modal-dialog-centered" style="width:55%;">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title" id="custom-width-modalLabel">Delete</h4>
                        <button type="button" class="close remove-data-from-delete-form" data-dismiss="modal" aria-hidden="true">×
                    <div class="modal-body">
                        <p>Do you want to delete this record?</p>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default waves-effect remove-data-from-delete-form"
                        <button type="button" class="btn btn-danger waves-effect waves-light deleteRecord">Delete

    {{--Firebase Tasks--}}
    <!-- The core Firebase JS SDK is always required and must be listed first -->
    <script src=""></script>

    <!-- TODO: Add SDKs for Firebase products that you want to use -->
    <script src=""></script>
    <script src=""></script>

        // Initialize Firebase
        var config = {
            apiKey: "{{ config('services.firebase.api_key') }}",
            authDomain: "{{ config('services.firebase.auth_domain') }}",
            databaseURL: "{{ config('services.firebase.database_url') }}",
            projectId: "{{ config('services.firebase.project_id') }}",
            storageBucket: "{{ config('services.firebase.storage_bucket') }}",
            messagingSenderId: "{{ config('services.firebase.messaging_sender_id') }}",
            appId: "{{ config('services.firebase.app_id') }}",
            measurementId: "{{ config('services.firebase.measurement_id') }}"

        var database = firebase.database();

        var lastIndex = 0;

        // Get Data
        firebase.database().ref('Users/').on('value', function (snapshot) {
            var value = snapshot.val();
            var htmls = [];
            $.each(value, function (index, value) {
                if (value) {
                    <td>' + + '</td>\
                    <td>' + + '</td>\
                    <td><button data-toggle="modal" data-target="#update-modal" class="btn btn-info updateData" data-id="' + index + '">Update</button>\
                    <button data-toggle="modal" data-target="#remove-modal" class="btn btn-danger removeData" data-id="' + index + '">Delete</button></td>\
                lastIndex = index;

        // Add Data
        $('#submitUser').on('click', function () {
            var values = $("#addUser").serializeArray();
            var name = values[0].value;
            var email = values[1].value;
            var userID = lastIndex + 1;


            firebase.database().ref('Users/' + userID).set({
                name: name,
                email: email,

            // Reassign lastID value
            lastIndex = userID;
            $("#addUser input").val("");

        // Update Data
        var updateID = 0;
        $('body').on('click', '.updateData', function () {
            updateID = $(this).attr('data-id');
            firebase.database().ref('Users/' + updateID).on('value', function (snapshot) {
                var values = snapshot.val();
                var updateData = '<div class="form-group">\
                    <label for="first_name" class="col-md-12 col-form-label">Name</label>\
                    <div class="col-md-12">\
                        <input id="first_name" type="text" class="form-control" name="name" value="' + + '" required autofocus>\
                <div class="form-group">\
                    <label for="last_name" class="col-md-12 col-form-label">Email</label>\
                    <div class="col-md-12">\
                        <input id="last_name" type="text" class="form-control" name="email" value="' + + '" required autofocus>\


        $('.updateUser').on('click', function () {
            var values = $(".users-update-record-model").serializeArray();
            var postData = {
                name: values[0].value,
                email: values[1].value,

            var updates = {};
            updates['/Users/' + updateID] = postData;



        // Remove Data
        $("body").on('click', '.removeData', function () {
            var id = $(this).attr('data-id');
            $('body').find('.users-remove-record-model').append('<input name="id" type="hidden" value="' + id + '">');

        $('.deleteRecord').on('click', function () {
            var values = $(".users-remove-record-model").serializeArray();
            var id = values[0].value;
            firebase.database().ref('Users/' + id).remove();
        $('.remove-data-from-delete-form').click(function () {
    <script src=""></script>



Step 7: Run Your Laravel Application

Start your Laravel development server:

php artisan serve



Congratulations! You've successfully set up Laravel 10 CRUD operations using Google Firebase. This powerful combination allows you to build scalable, real-time applications with ease.


You might also like:


Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.