Skip to Content
Housr PortalServicesFirebase Integration

Firebase Integration

The Portal uses Firebase Realtime Database for real-time chat functionality between tenants and agents/moderators.

Setup

Package: kreait/laravel-firebase (v5.3+)

Configuration

FIREBASE_DATABASE_URL=https://your-project.firebaseio.com FIREBASE_DATABASE_API_KEY=AIza... FIREBASE_CREDENTIALS={"type":"service_account","project_id":"...","private_key":"..."}

Note: FIREBASE_CREDENTIALS is stored as a JSON string in the environment variable, not as a file path.

Service Provider

File: app/Providers/FirebaseServiceProvider.php

Registers a singleton firebase binding that:

  1. Reads FIREBASE_CREDENTIALS env var as a JSON string
  2. Writes the credentials to a temporary file (/tmp/firebase_credentials.json)
  3. Creates a Firebase Factory with the service account and database URI
  4. Returns a Database instance
app('firebase') // Returns Kreait\Firebase\Database instance

Package Configuration

File: config/firebase.php

Standard kreait/laravel-firebase configuration with:

  • Default project: app
  • Credentials: file-based with auto-discovery enabled
  • Realtime Database URL from FIREBASE_DATABASE_URL
  • Caching via file store
  • Optional HTTP logging channels

Usage in the Portal

Chat System

Firebase Realtime Database powers the real-time chat between:

  • Tenants and Agents (enquiry conversations)
  • Moderators overseeing chat rooms

Relevant Livewire components:

  • app/Http/Livewire/Common/ChatArea.php — Main chat interface
  • app/Http/Livewire/Common/ChatMoreInfo.php — Chat details panel
  • app/Http/Livewire/Landlord/Communication/CommunicationContainer.php — Landlord chat wrapper

Data Flow

Client (Blade/Livewire) -> Firebase Realtime DB (real-time sync) -> Portal backend (via firebase singleton) for server-side operations

Chat messages are stored in both:

  1. Firebase Realtime Database — For real-time delivery to connected clients
  2. MySQL messages table — For persistence and querying via the Message model
  • Chat_room — Chat conversation records
  • Chat_room_member — Chat participants
  • Chat_room_moderation — Moderator assignments to chat rooms
  • Message — Persisted chat messages

Client-Side Firebase

Static Firebase assets are bundled from resources/assets/firebase/ and copied to the build output by the Vite static copy plugin. These include the Firebase JavaScript SDK for client-side real-time listeners.

Firebase Messaging

The Portal also uses Firebase Cloud Messaging (FCM) for push notifications. The kreait/laravel-firebase package provides the messaging API, used alongside the notification system:

  • Notification model — Push notification definitions
  • Notification_log — Send tracking
  • NotificationUtils — Utility class for sending notifications

Notes

  • The FirebaseServiceProvider uses a custom approach (writing credentials to a temp file) rather than the standard kreait/laravel-firebase credential discovery. This is because the credentials are stored as a JSON string in the environment rather than as a file path.
  • The Firebase configuration in config/firebase.php is the standard package config but may not be the primary path used — the custom FirebaseServiceProvider takes precedence for the firebase singleton.
Last updated on