🚀 Hostinger Optimized
🖥️ Server: LiteSpeed
💻 System: Linux s20058.bom1.stableserver.net 5.14.0-611.55.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue May 19 15:19:29 EDT 2026 x86_64
👤 User: skhata (1324)
🐘 PHP: 8.4.20
🚫 Disabled: ✨ NONE

💻 Terminal

📁 /home/skhata/chandrasons.com/public
$

📄 GoogleReviewsService.php

📁 Path: /home/skhata/chandrasons.com/app/Services/GoogleReviewsService.php
📊 Size: 1.92 KB
🔒 Perm: 0644
📝 MIME: text/x-php
<?php
namespace App\Services;

use Illuminate\Support\Facades\Http;
use App\Models\Setting;

class GoogleReviewsService {
    public function fetchReviews(string $placeId): array {
        $apiKey = Setting::get('google_maps_api_key') ?? config('services.google.maps_api_key');
        if (!$apiKey) throw new \Exception('Google Maps API key not configured in Site Settings.');

        $response = Http::timeout(15)->get('https://maps.googleapis.com/maps/api/place/details/json', [
            'place_id' => $placeId,
            'fields'   => 'reviews',
            'key'      => $apiKey,
        ]);

        if (!$response->ok()) throw new \Exception('Google Places API request failed: ' . $response->status());

        $data = $response->json();
        if (($data['status'] ?? '') !== 'OK') throw new \Exception('Google Places API error: ' . ($data['status'] ?? 'Unknown'));

        $reviews = $data['result']['reviews'] ?? [];

        return collect($reviews)
            ->filter(fn($r) => ($r['rating'] ?? 0) >= 4)
            ->map(fn($r) => [
                'source'          => 'google_review',
                'client_name'     => $r['author_name'],
                'quote'           => $r['text'],
                'rating'          => (int) $r['rating'],
                'photo'           => $r['profile_photo_url'] ?? null,
                'google_review_id' => md5($r['author_name'] . ($r['time'] ?? '')),
                'status'          => 'draft',
            ])
            ->values()
            ->toArray();
    }

    public function importToDrafts(string $placeId): int {
        $reviews = $this->fetchReviews($placeId);
        $imported = 0;
        foreach ($reviews as $review) {
            if (!\App\Models\Testimonial::where('google_review_id', $review['google_review_id'])->exists()) {
                \App\Models\Testimonial::create($review);
                $imported++;
            }
        }
        return $imported;
    }
}
← Back📥 Raw✏️ Edit🔒 Chmod
✨ File Manager Magic ✨