HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-26-0-120 6.17.0-1009-aws #9~24.04.2-Ubuntu SMP Fri Mar 6 23:50:29 UTC 2026 x86_64
User: ubuntu (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/www/html/dashboard.orbiwheels.com/app/Services/FirebaseService.php
<?php

namespace App\Services;

use App\Models\RideRequest;
use Kreait\Firebase\Factory;

class FirebaseService
{
    protected $database;

    public function __construct()
    {
        $factory = (new Factory)
            ->withServiceAccount(base_path(config('services.firebase.credentials')))
            ->withDatabaseUri(config('services.firebase.database_url'));

        $this->database = $factory->createDatabase();
    }

    public function pushRequest($transporter, $booking, $rideRequest)
    {
        return $this->database->getReference("transporters/{$transporter->id}/requests/{$rideRequest->id}")
                ->set([
                    'id' => $rideRequest->id,
                    'encrypted_id' => encrypt($rideRequest->id),
                    'booking_id' => $booking->id,
                    'ride_type' => $booking->ride_type_name,
                    'booking_type' => $booking->booking_type,
                    'pickup' => $booking->locations['pickup_location'] ?? '',
                    'drop'   => $booking->locations['drop_location'] ?? '',
                    'from_date' => $booking->dates['from_date'],
                    'to_date'   => $booking->dates['to_date'],
                    'pickup_time' => $booking->times['pickup_time'],
                    'return_time' => $booking->times['return_time'] ?? null,
                    'distance_km' => $booking->rides[0]->distance_km ?? '',
                    'fare' => number_format($booking->rides->sum('fare'), 2),
                    'status' => RideRequest::PENDING,
                    'created_at' => now()->toDateTimeString(),
                ]);
    }

    public function removeRequest($path)
    {
        return $this->database->getReference($path)->remove();
    }
}