How to Use Firebase Realtime Database with Laravel Without Any Package (Step-by-Step Guide)
Before Jumping towards the below integration you need the firebase database url
For that part log in to your firebase via this link - https://firebase.google.com/
Then you have to create a project. after creating a project you have the option like the below one, choose firebase real Realtime Database as shown in the below image.
Then click on the project overview -> project settings
Then generate the key and download the file
Firebase Realtime Database is a cloud-hosted NoSQL database that lets you store and sync data in real time across all clients. While many tutorials rely on Firebase PHP packages like kreait/firebase-php
, sometimes you want full control — or just prefer not to use any extra packages.
This blog will walk you through how to integrate Firebase Realtime Database in your Laravel application using just Laravel’s HTTP client and Firebase REST API, without installing any third-party packages.
Let’s get started.
Why Use Firebase Without a Package?
While Firebase PHP SDKs are convenient, sometimes:
- You want lightweight integration.
- You don’t want to install heavy dependencies.
- You need just basic CRUD operations.
- You want to learn how the underlying Firebase REST API works.
This approach gives you full control over how data is sent and received, and is useful for small or custom Firebase use cases.
Step 1: Set Up Firebase
First, create your Firebase project:
- Go to https://console.firebase.google.com
- Click “Add Project”
- Set a project name and enable/disable Google Analytics (optional)
- After creation, go to Build → Realtime Database
- Click “Create Database”
- Choose a location and start in test mode (only for development)
In test mode, anyone can read and write. Change this in security rules for production use.
Once created, you’ll get a Firebase Database URL, something like:
https://your-project-id.firebaseio.com/
Save this — we’ll need it in the Laravel .env
file.
Step 2: Configure Laravel Project
Step 2.1: Create a New Laravel App (if needed)
If you're starting from scratch:
Step 2.2: Add Firebase URL to .env
Open your .env
file and add:
Update config/services.php
if you want a central config:
Step 3: Create a Controller for Firebase Operations
Run the artisan command:
Open app/Http/Controllers/FirebaseController.php
and update it:
Step 4: Add Routes to web.php
Step 5: Test Your API
Start your Laravel server:
Now, try the following endpoints in your browser or Postman:
URLAction | |
/firebase/store | Stores new user in Firebase |
/firebase/fetch | Retrieves all user records |
/firebase/update/{id} | Updates the name of a user |
/firebase/delete/{id} | Deletes a user |
The {id}
should be the Firebase record key you get from store
or fetch
.
Firebase Structure Example
When you hit /firebase/store
, it sends:
Firebase auto-generates a unique ID:
Then, your data appears like:
To update or delete, pass that key (-NkqT3xkFBoP2ZUzEFX
) to the controller route.
Securing Your Firebase Database
After development, do not leave test mode enabled. Go to:
Firebase Console → Database → Rules, and set:
Then, you’ll need to add an auth token when accessing the REST API:
When the data will be stored, it will be shown in the below manner on firebase
You can generate a token using Firebase Authentication or admin SDK.
Benefits of This Approach
- No extra package dependencies
- Lightweight and fast
- Simple REST API design
- Great for server-to-server communication
- Easily extendable for more complex workflows
When Should You Use This?
This approach is best for:
- Internal dashboards
- Admin scripts
- Small web/mobile integrations
- Learning how Firebase works under the hood
If you're building a full-featured Firebase app, then use a proper Firebase SDK for advanced features like authentication, cloud messaging, file uploads, etc.
Bonus Tips
- Use Laravel Queues to sync Firebase in the background
- Add caching if reading frequently
- Use Form Requests to validate input before sending to Firebase
- Use a service class to abstract Firebase logic from controllers
Summary
You've now learned how to:
- Set up a Firebase project
- Use Laravel’s native HTTP client to interact with Firebase’s REST API
- Store, fetch, update, and delete data — all without any package
- Secure your Firebase database
- Extend your Laravel app to talk directly to Firebase
This approach is clean, flexible, and powerful for use cases where you want to avoid SDK bloat.
Resources
- Firebase REST API Docs: https://firebase.google.com/docs/reference/rest/database
- Laravel HTTP Client: https://laravel.com/docs/http-client
- Firebase Security Rules: https://firebase.google.com/docs/database/security
Would you like a follow-up blog on using Firebase Authentication, Firestore, or Cloud Messaging with Laravel? Just let me know — I’d be happy to help!
Download The Project Directly From Github
https://github.com/codehunger-team/firebase-real-time-database-with-laravel