aerni/google-maps
A Laravel package for adding Google Maps to your app with simple Blade components. Render interactive maps, place markers, and configure options through a clean PHP API, with no JavaScript required. Includes sensible defaults, publishable config, and support for custom map styling.
Install the package via Composer:
composer require <vendor>/<package>
Publish any config and migration files (if applicable):
php artisan vendor:publish --provider="<Vendor>\<Package>\<PackageServiceProvider>"
php artisan migrate
Look first at:
config/<package>.php – locale mappings and default formatting options.AddressFormatter) – the primary entry point for localized output.resources/lang/vendor/<package> – address format strings per locale.First use case: Store an address and render it using the current application locale.
use <Vendor>\<Package>\Models\Address;
$address = Address::create([
'line1' => '123 Main St',
'city' => 'Springfield',
'state' => 'IL',
'postal_code' => '62701',
'country' => 'US',
]);
// The formatter now respects app()->getLocale() (v0.4+)
echo $address->format(); // e.g. "123 Main St, Springfield, IL 62701"
Set the locale before formatting:
app()->setLocale('fr_FR');
echo $address->format(); // "123 Main St, 62701 Springfield (IL)"
Locale‑aware formatting in models
Use the package’s formatter directly or through model accessors:
// Explicit locale
$formatted = $address->format('de_DE');
// Site locale (v0.4)
$formatted = $address->format();
// In a Blade view
{{ $address->format() }}
Formatting in API resources
class AddressResource extends JsonResource
{
public function toArray($request)
{
return [
'formatted' => $this->format(), // uses request locale
'lines' => $this->toArray(),
];
}
}
Locale switching during a request
For multi‑locale sites, set the locale early (middleware, controller) so all address formatting uses the correct locale:
public function show(Address $address)
{
app()->setLocale($request->user()->locale);
return view('address.show', compact('address'));
}
Overriding format strings
Publish the package translations and edit the format strings for each locale:
// resources/lang/vendor/<package>/fr/address.php
return [
'format' => '{line1}, {postal_code} {city} ({state})',
];
Batch formatting
When rendering lists of addresses, set the locale once rather than per address:
app()->setLocale('es_ES');
$formatted = $addresses->map->format();
config('app.fallback_locale'). Verify your locale is present in the published translation files.app()->getLocale(). Ensure your middleware or controller sets it before any formatting occurs. Using App::setLocale() inside a view is too late for earlier calls.php artisan tinker to test formatting with different locales:
app()->setLocale('it_IT');
Address::first()->format();
config/<package>.php for a formatter key or use the provided extension points (e.g. macros on the formatter class).How can I help you explore Laravel packages today?