Does Laravel Work With Firebase?

Fully CompatibleLast verified: 2026-02-26

Laravel and Firebase work together seamlessly—use Firebase for auth and real-time data while Laravel handles your backend business logic and API layer.

Quick Facts

Compatibility
full
Setup Difficulty
Easy
Official Integration
No — community maintained
Confidence
high
Minimum Versions
Laravel: 8.0

How Laravel Works With Firebase

Laravel integrates with Firebase primarily through the Firebase Admin SDK for PHP, allowing you to authenticate users, access Firestore/Realtime Database, and manage Firebase services directly from your Laravel application. The typical architecture involves Laravel serving as your API backend while Firebase handles authentication (via Firebase Auth) and optionally real-time data synchronization. You install the Firebase SDK via Composer, initialize it with your service account credentials, and interact with Firebase services through dependency injection or facades. This is ideal when you want Laravel's routing, middleware, and ORM capabilities combined with Firebase's managed infrastructure. The developer experience is clean—Firebase handles scaling and real-time features while Laravel remains your familiar request-response handler. One common pattern is using Laravel as a REST/GraphQL API that validates requests and delegates data operations to Firestore, with Firebase Auth tokens validated via Laravel middleware to secure your endpoints.

Best Use Cases

Real-time chat or collaboration apps where Firebase handles messaging sync and Laravel manages user relationships and business logic
Progressive web apps needing hybrid authentication (Firebase Auth on frontend, Laravel API validation)
Serverless-adjacent architectures where Cloud Functions complement Laravel's scheduled tasks and queues
Multi-tenant SaaS platforms using Laravel for account management and Firebase for isolated real-time document databases per tenant

Quick Setup

bash
composer require kreait/firebase-php
php
<?php

namespace App\Services;

use Kreait\Firebase\Factory;

class FirebaseService
{
    protected $database;

    public function __construct()
    {
        $factory = (new Factory())
            ->withServiceAccount(config('firebase.credentials'));
        $this->database = $factory->createDatabase();
    }

    public function getUser($uid)
    {
        return $this->database
            ->getReference('users/' . $uid)
            ->getValue();
    }

    public function saveUser($uid, $data)
    {
        $this->database
            ->getReference('users/' . $uid)
            ->set($data);
    }
}

// In your Laravel controller:
app(FirebaseService::class)->saveUser('user123', ['name' => 'John']);

Known Issues & Gotchas

critical

Firebase Admin SDK requires a service account JSON file with sensitive credentials

Fix: Store the JSON file outside your web root, load via environment variables, and never commit to version control. Use Laravel's config system to manage the path securely.

warning

Firestore queries lack some SQL capabilities like complex JOINs, making data modeling different from traditional Laravel/SQL patterns

Fix: Design your Firestore schema with denormalization in mind. Use Laravel's API endpoints to aggregate and join data server-side rather than expecting Firestore to do it.

warning

Firebase Auth tokens expire quickly (1 hour) and refresh tokens have longer lifespans, requiring careful token management in your Laravel API

Fix: Implement middleware to validate Firebase ID tokens and refresh them as needed. Cache validation results to reduce repeated API calls.

info

Firestore's free tier has limits on read/write operations that scale poorly with typical Laravel request volumes

Fix: Cache responses using Laravel's cache drivers (Redis/Memcached) to reduce database hits and plan billing accordingly.

Alternatives

  • Laravel + AWS (DynamoDB/Cognito): More control but requires more setup; better for complex relational needs
  • Laravel + Supabase: Open-source Firebase alternative with PostgreSQL backend, easier if you prefer SQL
  • Next.js/Nuxt + Firebase: Full frontend-to-backend JavaScript stack without a separate API layer

Resources

Related Compatibility Guides

Explore more compatibility guides