illuma-law/laravel-places-scout
Composer 安装命令:
composer require illuma-law/laravel-places-scout
包简介
A fluent Laravel package for interacting with the Google Places API with strongly typed DTOs.
README 文档
README
A fluent Laravel package for interacting with the Google Places API using strictly typed DTOs.
Places Scout acts as a dedicated abstraction over the Google Maps Places API. Instead of dealing directly with raw HTTP requests and unstructured JSON arrays, this package provides an elegant, object-oriented API that maps Google's responses directly into fully typed PHP 8.3 Data Transfer Objects (DTOs) with IDE autocompletion out of the box.
Features
- Text Search: Search for places using natural text queries with automatic pagination support.
- Place Details: Retrieve highly detailed information (phone, website, coordinates) about specific places using their Place ID.
- Strongly Typed DTOs: Immutable,
readonlydata transfer objects ensure data integrity. - Fluent Interface: Clean, chainable API via Facade or Dependency Injection.
- Multi-Tenant Friendly: Supports overriding API keys on the fly.
- Graceful Error Handling: Suppresses exceptions on failed API requests (logging them instead) and returns
null, preventing your application from crashing due to third-party API instability.
Installation
You can install the package via composer:
composer require illuma-law/laravel-places-scout
Publish the configuration file:
php artisan vendor:publish --tag="places-scout-config"
Configuration
Add your Google Places API key to your .env file:
GOOGLE_PLACES_API_KEY=your_api_key_here
The published config/places-scout.php will use this key automatically:
return [ /** * Your Google Places API Key. * Obtain an API key from the Google Cloud Console: * https://console.cloud.google.com/google/maps-apis/credentials */ 'api_key' => env('GOOGLE_PLACES_API_KEY'), ];
Usage & Integration
Text Search
Search for places using a text query. It returns a PlaceSearchResponse DTO containing an array of PlaceSearchResult DTOs.
use IllumaLaw\PlacesScout\Facades\PlacesScout; // Basic text search $response = PlacesScout::textSearch('Law firms in New York'); if ($response) { foreach ($response->results as $result) { echo $result->name; // 'Smith & Associates' echo $result->placeId; // 'ChIJ...' echo $result->formattedAddress; // '123 Main St, New York, NY' echo $result->latitude; // 40.7128 echo $result->longitude; // -74.0060 echo $result->rating; // 4.8 } // Handle pagination using the nextPageToken if ($response->nextPageToken) { $nextPage = PlacesScout::textSearch('Law firms in New York', $response->nextPageToken); } }
Place Details
Get detailed information about a specific place using its place_id. Returns a PlaceDetails DTO.
use IllumaLaw\PlacesScout\Facades\PlacesScout; $details = PlacesScout::getPlaceDetails('ChIJN1t_tDeuEmsRUsoyG83frY4'); if ($details) { echo $details->name; // 'Google Australia' echo $details->phoneNumber; // '(02) 9374 4000' echo $details->website; // 'https://www.google.com.au/' echo $details->formattedAddress; // '48 Pirrama Rd, Pyrmont NSW 2009, Australia' echo $details->rating; // 4.4 echo $details->userRatingsTotal; // 123 echo $details->latitude; // -33.866651 echo $details->longitude; // 151.195827 }
Dynamic API Keys (Multi-tenant support)
If your application allows users to provide their own Google Maps API credentials, you can override the default API key fluently per-request:
use IllumaLaw\PlacesScout\Facades\PlacesScout; $userApiKey = $user->settings->google_api_key; // Override API key for this specific request $response = PlacesScout::withApiKey($userApiKey)->textSearch('Restaurants in Paris');
Dependency Injection
Instead of the Facade, you can inject the PlacesScoutService directly into your controllers or jobs:
namespace App\Http\Controllers; use IllumaLaw\PlacesScout\PlacesScoutService; class LocationController extends Controller { public function __construct( private PlacesScoutService $placesScout ) {} public function search(string $query) { $results = $this->placesScout->textSearch($query); return response()->json($results); } }
Testing
The package includes a comprehensive Pest test suite and requires 100% test coverage.
composer test
License
The MIT License (MIT). Please see License File for more information.
illuma-law/laravel-places-scout 适用场景与选型建议
illuma-law/laravel-places-scout 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 62 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「fluent」 「laravel」 「dto」 「google-places」 「scout」 「places-api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 illuma-law/laravel-places-scout 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 illuma-law/laravel-places-scout 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 illuma-law/laravel-places-scout 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Presentation and Formatting helper with nice fluent interface.
PHP library for the MUMSYS project
A simple library that allows transform any kind of data to native php data or whatever
Traits gathering fluent syntax common methods
A modern, fluent HTTP client. Forked from Mashape, reimagined by Nidux, and open-sourced for the PHP community.
A fluent PHP CURL wrapper
统计信息
- 总下载量: 62
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 39
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-20