- How do I install and set up blade-country-flags in Laravel?
- Run `composer require stijnvanouplines/blade-country-flags` to install. No additional setup is required for basic usage, but publish the config with `php artisan vendor:publish --tag=blade-country-flags-config` to customize defaults like classes or attributes. Ensure Blade Icons is installed for full functionality.
- What Laravel and PHP versions does this package support?
- The package requires **PHP 7.4+** and **Laravel 8.0+**. It’s compatible with modern Laravel versions up to 11.x, but test thoroughly if using legacy versions (e.g., 7.x). Check the [GitHub actions](https://github.com/stijnvanouplines/blade-country-flags/actions) for latest compatibility updates.
- Can I use dynamic country codes (e.g., from a database) with @countryFlag?
- Yes. Pass a variable directly: `@countryFlag($user->country)`. The directive resolves the country code to the corresponding SVG flag. For example, `@countryFlag('US')` renders the U.S. flag. Supports ISO 3166-1 alpha-2 codes (e.g., 'BE', 'JP').
- How do I customize flag sizes or styles in Blade?
- Use the `4x3` (default) or `1x1` (square) variants with classes or inline styles. Example: `<x-flag-4x3-be class='w-8 h-8' />` or `<x-flag-1x1-be style='width: 2rem' />`. Publish the config to set global defaults for all flags.
- Are the flags self-hosted or fetched from an external source?
- Flags are **bundled as SVGs** via `flag-icon-css` and served as static assets. No external API calls are made during runtime. Publish the assets to `public/vendor/flags` with `php artisan vendor:publish --tag=blade-country-flags-assets` for offline use.
- Does this package work with Laravel Vite/Mix for asset optimization?
- Yes. The SVG flags can be processed by Vite/Mix if published as assets. Use `@vite(['resources/css/flags.css'])` in your layout to ensure flags are bundled. For dynamic flags, verify the Blade directive compiles correctly in your build pipeline.
- How do I handle missing or unsupported country codes?
- The package includes a fallback mechanism. If a country code isn’t found, it renders a generic flag or a text label (configurable via the published config). Override defaults in `config/blade-country-flags.php` under `fallback` to customize behavior.
- Can I use these flags in API responses (JSON) or non-Blade contexts?
- This package is **Blade-specific**. For APIs, manually return the SVG markup or use a helper like `Flag::svg('US')` if the package exposes one. Alternatively, fetch flags via `flag-icon-css` directly in your frontend (e.g., React/Vue) or backend logic.
- What are the performance implications of using SVG flags?
- SVGs are lightweight and scalable, but bundle size increases with the number of flags. Enable Blade Icons caching (`config/blade-icons.php`) to reduce recompilation overhead. For large apps, lazy-load flags or use a CDN for `flag-icon-css`. Test with Laravel Debugbar to monitor asset impact.
- Are there alternatives to blade-country-flags for Laravel?
- Yes. Consider **spatie/laravel-country-flags** (for dynamic flag generation) or **laravel-flag** (for API-based flags). For static SVGs, manually include `flag-icon-css` via CDN or use Laravel’s `asset()` helper. This package stands out for its **Blade-centric, zero-config** approach.