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:
- Reads
FIREBASE_CREDENTIALSenv var as a JSON string - Writes the credentials to a temporary file (
/tmp/firebase_credentials.json) - Creates a Firebase Factory with the service account and database URI
- Returns a
Databaseinstance
app('firebase') // Returns Kreait\Firebase\Database instancePackage 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 interfaceapp/Http/Livewire/Common/ChatMoreInfo.php— Chat details panelapp/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 operationsChat messages are stored in both:
- Firebase Realtime Database — For real-time delivery to connected clients
- MySQL
messagestable — For persistence and querying via theMessagemodel
Related Models
Chat_room— Chat conversation recordsChat_room_member— Chat participantsChat_room_moderation— Moderator assignments to chat roomsMessage— 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:
Notificationmodel — Push notification definitionsNotification_log— Send trackingNotificationUtils— Utility class for sending notifications
Notes
- The
FirebaseServiceProvideruses a custom approach (writing credentials to a temp file) rather than the standardkreait/laravel-firebasecredential 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.phpis the standard package config but may not be the primary path used — the customFirebaseServiceProvidertakes precedence for thefirebasesingleton.