yahaaylabs/laravel-barangay-search
Install the Package
composer require yahaaylabs/laravel-barangay-search
Ensure your composer.json meets the requirements (PHP 8.1+, Laravel 10/11, Livewire 3).
Set Up API Key
Register for a GIS.PH API key and add it to your .env:
GIS_PH_API_KEY=your_api_key_here
Basic Livewire Integration
In a Livewire component (e.g., BarangaySearchComponent.php), include the component:
use YahaayLabs\BarangaySearch\BarangaySearch;
public function render()
{
return view('livewire.barangay-search-component', [
'barangaySearch' => BarangaySearch::make()
->debounce(500) // Optional: Adjust debounce time (ms)
->cacheFor(60) // Optional: Cache results for 60 minutes
]);
}
Render the Component in Blade
@livewire('barangay-search-component')
Handle Selected Barangay Extend the component to capture selections:
public function selected(Barangay $barangay)
{
$this->dispatch('barangay-selected', barangay: $barangay);
}
Autocomplete Search
BarangaySearch::make()
->filterByProvince('Laguna')
->filterByCity('Calamba')
Mary UI Integration (Optional)
php artisan vendor:publish --tag=barangay-search-views
Caching Strategy
BarangaySearch::make()->cacheFor(3600); // Cache for 1 hour
BarangaySearch::flushCache();
Event Handling
protected $listeners = ['barangay-selected' => 'handleBarangaySelection'];
public function handleBarangaySelection($event)
{
$this->barangay = $event['barangay'];
}
Custom UI
@livewire('barangay-search-component', [
'barangaySearch' => BarangaySearch::make()->customView('path.to.your.view')
])
public function rules()
{
return [
'barangay' => 'required|string',
];
}
config/barangay-search.php to adjust max_retries or timeout.API Key Validation
GIS_PH_API_KEY in .env causes silent failures.GisPhSdkException.Caching Conflicts
BarangaySearch::flushCache();
Livewire Component Naming
BarangaySearchComponent vs. LocationPicker).Debounce Delays
BarangaySearch::make()->debounce($this->isMobile() ? 300 : 500);
Mary UI Dependencies
npm install mary-ui
npm run dev
config/barangay-search.php:
'debug' => env('BARANGAY_SEARCH_DEBUG', false),
https://gis.ph/api/barangays.Custom Data Mapping
Barangay model to add custom fields:
use YahaayLabs\BarangaySearch\Models\Barangay as BaseBarangay;
class Barangay extends BaseBarangay
{
protected $appends = ['full_address'];
public function getFullAddressAttribute()
{
return "{$this->barangay}, {$this->municipality}, {$this->province}";
}
}
Batch Processing
$barangays = BarangaySearch::make()->search('Calamba')->getBarangays();
Geocoding Integration
use Geocoder\Geocoder;
$geocoder = new Geocoder();
$coordinates = $geocoder->geocode($barangay->full_address);
Localization
'labels' => [
'search_placeholder' => 'Search for a barangay...',
'no_results' => 'No barangays found.',
],
How can I help you explore Laravel packages today?