stijnvanouplines/blade-country-flags
Laravel package providing country flag SVGs as Blade components, powered by Blade Icons and flag-icon-css. Use 4x3 or 1x1 variants like , with support for classes/styles and configurable defaults via a published config.
@countryFlag) to embed country flags dynamically, reducing clutter in controllers and models.Blade::directive()) suggests low friction. Example usage:
@countryFlag('US') <!-- Renders flag for United States -->
file_get_contents() or similar for asset loading. Potential issues if flags are hosted externally (CORS, latency).public/storage/flags/).view cache, CDN, or browser cache)?alt text for screen readers? Does the package support this?<img> tags, third-party services like CountryFlags).@countryFlag() and test rendering.User::country → @countryFlag($user->country))./flags/{code}.svg) or relative paths (storage/flags/{code}.svg).view caching or middleware to cache flag responses if dynamic fetching is used.composer require stijnvanouplines/blade-country-flags
Register the directive in AppServiceProvider:
use Stijnvanouplines\BladeCountryFlags\BladeCountryFlagsServiceProvider;
public function register()
{
$this->app->register(BladeCountryFlagsServiceProvider::class);
}
.env:
FLAGS_ASSET_PATH=storage/flags
FLAGS_API_URL=https://api.countryflags.io/v1
storage/flags or CDN.composer.json if stability is critical.Blade::directive('countryFlag', function ($code) {
Log::debug("Rendering flag for: $code");
// ...
});
storage/flags).asset() helper or mix() to optimize paths.Route::middleware(['cache.flags'])->group(function () {
// Routes that fetch flags dynamically
});
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Flag assets missing (404) | Broken UI, user confusion | Fallback to text label or default flag icon. |
| External API downtime | Flags fail to render | Cache responses locally; use a backup API. |
| Blade directive syntax error | Entire view breaks | Validate directive usage in CI/CD. |
| High asset bandwidth usage | Slow page loads | Compress SVGs/PNGs; use CDN. |
| Unsupported country code | No flag displayed | Log errors; add a "Contact Admin" link. |
<!-- Renders flag for user's country -->
@countryFlag($user->country, ['size' => 'small', 'class' => 'rounded'])
How can I help you explore Laravel packages today?