1. Go to this page and download the library: Download blashbrook/papiclient library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
blashbrook / papiclient example snippets
class YourComponent extends Component
{
public $deliveryOptionIDChanged;
public function mount()
{
$this->deliveryOptionIDChanged = session('DeliveryOptionID', 8);
}
public function updatedDeliveryOptionIDChanged($value)
{
session(['DeliveryOptionID' => $value]);
}
}
private $availableDeliveryOptions = [
'Mailing Address' => 'Mail', // Database value => Display name
'Email Address' => 'Email', // Database value => Display name
'Phone 1' => 'Phone', // Database value => Display name
'TXT Messaging' => 'Text Messaging' // Database value => Display name
];
class YourParentComponent extends Component
{
public $deliveryOptionIDChanged;
public function mount()
{
// Set from session (recommended)
$this->deliveryOptionIDChanged = session('DeliveryOptionID', 8);
// OR set from user preference
// $this->deliveryOptionIDChanged = auth()->user()->preferred_delivery_option ?? 8;
// OR set hardcoded default
// $this->deliveryOptionIDChanged = 8;
}
// Optional: Update session when value changes
public function updatedDeliveryOptionIDChanged($value)
{
session(['DeliveryOptionID' => $value]);
}
}
class YourComponent extends Component
{
public $selectedSchool;
public function mount()
{
$this->selectedSchool = session('PatronUDF_School', '');
}
#[On('patronUdfUpdated')]
public function handleUdfUpdate($data)
{
if ($data['label'] === 'School') {
$this->selectedSchool = $data['value'];
// Handle school selection logic here
}
}
}
class AddressComponent extends Component
{
public $selectedPostalCode;
public $userCity;
public $userState;
public function mount()
{
$this->selectedPostalCode = session('PostalCodeID', null);
}
#[On('postalCodeUpdated')]
public function handlePostalCodeUpdate($data)
{
$this->userCity = $data['city'];
$this->userState = $data['state'];
// Auto-populate address fields
$this->updateAddressFromPostalCode($data);
}
private function updateAddressFromPostalCode($postalData)
{
// Handle postal code selection logic
$this->dispatch('addressUpdated', $postalData);
}
}
// When user selects a new postal code:
// 1. updatedSelectedPostalCodeChanged() fires automatically
// 2. Session is updated: session(['PostalCodeID' => $newValue])
// 3. Event is dispatched: postalCodeUpdated with full location data
// 4. Parent component receives event and can update other fields
class YourComponent extends Component
{
public $selectedSchool;
public function mount()
{
$this->selectedSchool = session('PatronUDF_School', '');
}
#[On('patronUdfUpdated')]
public function handleUdfUpdate($data)
{
if ($data['label'] === 'School') {
$this->selectedSchool = $data['value'];
// Handle school selection logic here
}
}
}
// In your component
public function mount()
{
$this->selectedGrade = session('PatronUDF_Grade', '');
}
public function updatedSelectedGrade($value)
{
session(['PatronUDF_Grade' => $value]);
}
#[On('patronUdfUpdated')]
public function handlePatronUdfUpdate($data)
{
// $data contains:
// - 'label': The UDF label (e.g., 'School')
// - 'value': Selected value (e.g., 'High School')
// - 'displayName': Display name (customizable)
match($data['label']) {
'School' => $this->updateSchoolPreferences($data['value']),
'Department' => $this->updateDepartmentSettings($data['value']),
default => null
};
}
// Create a custom component extending PatronUDFSelectFlux
class CustomSchoolSelectFlux extends PatronUDFSelectFlux
{
protected function getCustomDisplayName(string $value): string
{
return match($value) {
'Elementary School' => '🏫 Elementary (K-5)',
'Middle School' => '🏛️ Middle School (6-8)',
'High School' => '🎓 High School (9-12)',
'College' => '🏛️ College/University',
default => $value
};
}
}
class AddressComponent extends Component
{
public $selectedPostalCode;
public $userCity;
public $userState;
public function mount()
{
$this->selectedPostalCode = session('PostalCodeID', null);
}
#[On('postalCodeUpdated')]
public function handlePostalCodeUpdate($data)
{
$this->userCity = $data['city'];
$this->userState = $data['state'];
// Auto-populate address fields
$this->updateAddressFromPostalCode($data);
}
private function updateAddressFromPostalCode($postalData)
{
// Handle postal code selection logic
$this->dispatch('addressUpdated', $postalData);
}
}
public $selectedState = 'CO';
public $availablePostalCodes = [];
public function updatedSelectedState($state)
{
// Re-render postal code component with new filter
$this->dispatch('updatePostalCodeFilter', ['State' => $state]);
}
class AddressFormComponent extends Component
{
public $selectedPostalCode;
public $address = [
'city' => '',
'state' => '',
'postal_code' => '',
'county' => ''
];
#[On('postalCodeUpdated')]
public function handlePostalCodeSelection($data)
{
$this->address = [
'city' => $data['city'],
'state' => $data['state'],
'postal_code' => $data['postalCode'],
'county' => $data['county']
];
// Auto-populate form fields
$this->dispatch('addressFieldsUpdated', $this->address);
}
}
#[On('postalCodeUpdated')]
public function handlePostalCodeUpdate($data)
{
// $data contains:
// - 'id': Database ID
// - 'postalCodeId': PostalCodeID field
// - 'city': City name
// - 'state': State abbreviation
// - 'postalCode': Postal code
// - 'county': County name
// - 'countryId': Country ID
// - 'displayText': Formatted display string
$this->updateLocationPreferences($data);
$this->loadNearbyServices($data['postalCode']);
$this->calculateShippingCosts($data);
}
// Manual session management
public function mount()
{
$this->selectedPostalCode = session('PostalCodeID', null);
}
public function updatedSelectedPostalCode($value)
{
session(['PostalCodeID' => $value]);
}
class CustomPostalCodeSelectFlux extends PostalCodeSelectFlux
{
protected function customFormatDisplay(PostalCode $postalCode): string
{
return "{$postalCode->City} ({$postalCode->PostalCode}) - {$postalCode->County}";
}
}
public function searchPostalCodes($searchTerm)
{
$this->filterOptions($searchTerm);
$this->render(); // Re-render with filtered options
}
// In a custom extended component
protected function loadPostalCodes(): void
{
$this->options = PostalCode::select(/* fields */)
->limit(500) // Limit initial load
->get();
}
`
use Blashbrook\PAPIClient\PAPIClient;
protected PAPIClient $papiclient;
public function __construct(PAPIClient $papiclient) {
$this->papiclient = $papiclient;
}
use Blashbrook\PAPIClient\PAPIClient;
protected PAPIClient $papiclient;
public function boot(PAPIClient $papiclient) {
$this->papiclient = $papiclient;
}
bash
php artisan test --filter=DeliveryOptionSelectFluxTest
Tests/
├── Unit/
│ ├── PatronUDFSelectFluxTest.php # Unit tests for PatronUDF component
│ ├── PostalCodeSelectFluxTest.php # Unit tests for PostalCode component
│ └── PAPIClientTest.php # Unit tests for API client
├── Feature/
│ ├── LivewireComponentsTest.php # Feature tests for all components
│ └── PAPIClientTest.php # Feature tests for API client
└── Integration/
└── PAPIClientIntegrationTest.php # Integration tests with real API