yahaaylabs/laravel-barangay-search
Composer 安装命令:
composer require yahaaylabs/laravel-barangay-search
包简介
A Laravel Livewire component for searching Philippine Barangays with Mary UI support
README 文档
README
A Laravel Livewire component for searching Philippine Barangays with optional Mary UI support. This package uses the GIS.PH SDK to interact with the official GIS.PH API.
Features
- 🔍 Autocomplete Search - Real-time Barangay Search with debouncing
- 🎨 Mary UI Support - Pre-styled components using Mary UI (optional)
- 💾 Caching - Intelligent caching to reduce API calls
- 🎯 Filtering - Filter by municipality, city, or province
- 🔧 Customizable - Fully customizable UI and behavior
- ⚡ Fast - Optimized for performance
- 📦 Easy Integration - Drop-in component for any Laravel Livewire app
Requirements
- PHP 8.1 or higher
- Laravel 10.x or 11.x
- Livewire 3.x
- GIS.PH API Key
Installation
1. Install via Composer
composer require yahaaylabs/laravel-barangay-search
2. Publish Configuration (Optional)
php artisan vendor:publish --tag=barangay-search-config
3. Publish Views (Optional)
If you want to customize the views:
php artisan vendor:publish --tag=barangay-search-views
4. Set Your API Key
Add your GIS.PH API key to your .env file:
GISPH_API_KEY=your_api_key_here
Get your API key from https://gis.ph
Quick Start
Basic Usage
<livewire:barangay-search wire:model="selectedBarangay" label="Select Barangay" placeholder="Search for a barangay..." />
With Form Integration
<x-form wire:submit="save"> <x-input label="Name" wire:model="name" /> <livewire:barangay-search wire:model="form.barangay" label="Barangay" :required="true" hint="Start typing to search" /> <x-slot:actions> <x-button label="Cancel" link="/dashboard" /> <x-button label="Save" type="submit" spinner="save" /> </x-slot:actions> </x-form>
Listening to Events
<livewire:barangay-search wire:model="barangay" /> @script <script> $wire.on('barangay-selected', (event) => { console.log('Selected:', event.barangay); // Do something with the selected barangay }); $wire.on('barangay-cleared', () => { console.log('Selection cleared'); }); $wire.on('barangay-search-error', (event) => { console.error('Search error:', event.error); }); </script> @endscript
Component Props
| Prop | Type | Default | Description |
|---|---|---|---|
wire:model |
mixed | null |
Bind the selected barangay |
label |
string | '' |
Label text above the input |
placeholder |
string | Config value | Placeholder text for the input |
required |
boolean | false |
Mark field as required |
clearable |
boolean | true |
Show clear button |
hint |
string | '' |
Helper text below the input |
municipalityCode |
string | null |
Filter results by municipality code |
cityCode |
string | null |
Filter results by city code |
provinceCode |
string | null |
Filter results by province code |
containerClass |
string | '' |
Additional CSS classes for container |
inputClass |
string | '' |
Additional CSS classes for input |
Advanced Usage
Filtering by Municipality
<livewire:barangay-search wire:model="barangay" :municipality-code="$selectedMunicipalityCode" label="Select Barangay" />
Filtering by Province
<livewire:barangay-search wire:model="barangay" :province-code="$selectedProvinceCode" label="Select Barangay in {{ $provinceName }}" />
Custom Styling
<livewire:barangay-search wire:model="barangay" container-class="my-custom-class" input-class="custom-input-style" />
Using Without Mary UI
If you don't want to use Mary UI styling, update your config:
// config/barangay-search.php 'ui' => [ 'use_mary_ui' => false, // Use vanilla styling ],
Configuration
The configuration file config/barangay-search.php provides several customization options:
return [ 'api_key' => env('GISPH_API_KEY'), 'cache' => [ 'enabled' => true, 'ttl' => 3600, // 1 hour 'prefix' => 'barangay_search', ], 'search' => [ 'min_query_length' => 2, 'debounce_ms' => 300, 'max_results' => 20, ], 'ui' => [ 'placeholder' => 'Search for a barangay...', 'no_results_text' => 'No barangays found', 'loading_text' => 'Searching...', 'use_mary_ui' => true, ], ];
Using the Service Directly
You can also use the BarangayService directly in your controllers or other classes:
use YahaayLabs\LaravelBarangaySearch\Services\BarangayService; class YourController extends Controller { public function __construct( protected BarangayService $barangayService ) {} public function search(Request $request) { $results = $this->barangayService->search( query: $request->input('q'), filters: [ 'municipality_code' => $request->input('municipality_code') ] ); return response()->json($results); } public function getByCode(string $code) { $barangay = $this->barangayService->getByCode($code); return response()->json($barangay); } public function getByMunicipality(string $municipalityCode) { $barangays = $this->barangayService->getByMunicipality($municipalityCode); return response()->json($barangays); } }
Response Format
When a barangay is selected, the component returns an array with the following structure:
[
'code' => '012345678',
'name' => 'Barangay Name',
'municipality' => 'Municipality Name',
'municipality_code' => '012345',
'city' => 'City Name', // nullable
'city_code' => '012345', // nullable
'province' => 'Province Name',
'province_code' => '0123',
'region' => 'Region Name',
'region_code' => '01',
'full_address' => 'Barangay Name, Municipality Name, Province Name',
]
Events
The component dispatches the following events:
barangay-selected
Fired when a barangay is selected from the dropdown.
$wire.on('barangay-selected', (event) => { console.log(event.barangay); // Selected barangay object });
barangay-cleared
Fired when the selection is cleared.
$wire.on('barangay-cleared', () => { // Handle clear action });
barangay-search-error
Fired when a search error occurs.
$wire.on('barangay-search-error', (event) => { console.error(event.error); // Error message });
Caching
The package includes built-in caching to reduce API calls:
// Clear all cached searches use YahaayLabs\LaravelBarangaySearch\Services\BarangayService; app(BarangayService::class)->clearCache();
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Security
If you discover any security-related issues, please email security@yahaaylabs.com instead of using the issue tracker.
Credits
- YahaayLabs
- Built using GIS.PH SDK
- Powered by GIS.PH API
License
The MIT License (MIT). Please see License File for more information.
Support
For support, email support@yahaaylabs.com or visit our documentation.
yahaaylabs/laravel-barangay-search 适用场景与选型建议
yahaaylabs/laravel-barangay-search 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「gis」 「philippines」 「barangay」 「livewire」 「mary-ui」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yahaaylabs/laravel-barangay-search 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yahaaylabs/laravel-barangay-search 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yahaaylabs/laravel-barangay-search 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
QuadTree implementation in PHP
Philippines region, province, cities/municipalities and barangays Laravel migration and table seeder.
A library to manipulate KML/KMZ files
PHP FFI bindings for Uber's H3 hexagonal hierarchical geospatial indexing system
Cowegis GeoJSON - PHP GeoJSON specification (RFC 7946) implementation
Open-source native PHP library for doing geometry operations. Can read and write a wide variety of formats: (E)WKT, (E)WKB, TWKB, GeoJSON, KML, GPX, GeoRSS. Works with all Simple-Feature geometries (Point, LineString, Polygon...) and can be used to get centroids, bounding-boxes, area, etc.
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-15