Location
Direktori: app/Services/Location/
Mendeteksi negara user secara otomatis menggunakan scoring berbobot dari beberapa sinyal — kode telepon, bahasa browser, timezone, dan IP.
Ringkasan
AutoDetectService menggabungkan empat sinyal untuk menentukan kode negara 3-huruf (contoh: IDN, MYS, SGP). Masing-masing sinyal punya bobot yang berkontribusi ke skor akhir.
Kenapa Ada
Tanpa service ini, user harus memilih negara secara manual di setiap form. Service ini pre-fill field negara dengan tebakan terbaik.
Algoritma
Kode telepon ─── 40% ──┐
Bahasa browser ── 30% ──┤──► Total skor ──► Tertinggi menang
Timezone ─── 20% ──┘| Sinyal | Bobot | Sumber | Contoh |
|---|---|---|---|
| Kode telepon | 40% | Input phone | +62 → IDN |
| Bahasa browser | 30% | Header Accept-Language | id-ID → IDN |
| Timezone | 20% | Cookie timezone | Asia/Jakarta → IDN |
Fallback: IDN (Indonesia).
Cara Pakai
php
$detector = app(AutoDetectService::class);
$countryCode = $detector->detect($request);
// Kembali: 'IDN', 'MYS', 'SGP', dll.File Penting
| File | Tujuan |
|---|---|
app/Services/Location/AutoDetectService.php | Deteksi negara berbobot |
app/Models/Geographic/Country/Country.php | Tabel countries — code, iso2, phone_code |