Skip to content

Laravel Barangay Search

A Laravel Livewire component for searching Philippine Barangays with optional Mary UI support. This package uses the GIS.PH PHP SDK to interact with the official GIS.PH API.

GitHub Repository: YahaayLabs/laravel-barangay-search

  • 🔍 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.
Terminal window
composer require yahaaylabs/laravel-barangay-search
Terminal window
php artisan vendor:publish --tag=barangay-search-config

If you want to customize the component views:

Terminal window
php artisan vendor:publish --tag=barangay-search-views

Add your GIS.PH API key to your .env file:

GISPH_API_KEY=your_api_key_here

Get your API key from the GIS.PH Dashboard.

<livewire:barangay-search
wire:model="selectedBarangay"
label="Select Barangay"
placeholder="Search for a barangay..."
/>
<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>
<livewire:barangay-search wire:model="barangay" />
@script
<script>
$wire.on('barangay-selected', (event) => {
console.log('Selected:', event.barangay);
// Do something with the selected barangay object
});
$wire.on('barangay-cleared', () => {
console.log('Selection cleared');
});
$wire.on('barangay-search-error', (event) => {
console.error('Search error:', event.error);
});
</script>
@endscript
PropTypeDefaultDescription
wire:modelmixednullBind the selected barangay.
labelstring''Label text above the input.
placeholderstringConfig valuePlaceholder text for the input.
requiredbooleanfalseMark field as required.
clearablebooleantrueShow clear button.
hintstring''Helper text below the input.
municipalityCodestringnullFilter results by municipality code.
cityCodestringnullFilter results by city code.
provinceCodestringnullFilter results by province code.
containerClassstring''Additional CSS classes for container.
inputClassstring''Additional CSS classes for input.
<!-- Filter by Province Code -->
<livewire:barangay-search
wire:model="barangay"
:province-code="$selectedProvinceCode"
label="Select Barangay"
/>

If you prefer to style the component using vanilla Tailwind CSS/CSS instead of Mary UI components, disable it in config/barangay-search.php:

config/barangay-search.php
'ui' => [
'use_mary_ui' => false,
],

When a barangay is selected, the component binds an array structure:

[
'code' => '0701201001',
'name' => 'Bahi',
'municipality' => 'Alburquerque',
'municipality_code' => '0701201000',
'city' => null,
'city_code' => null,
'province' => 'Bohol',
'province_code' => '0701200000',
'region' => 'Central Visayas',
'region_code' => '0700000000',
'full_address' => 'Bahi, Alburquerque, Bohol',
]

To optimize and speed up requests, the package caches query results. You can clear cached queries using the service:

use YahaayLabs\LaravelBarangaySearch\Services\BarangayService;
app(BarangayService::class)->clearCache();