- How do I install spatie/emoji in a Laravel application?
- Run composer require spatie/emoji. The package has no service provider, middleware, or config file, so there is nothing to register or publish. You can immediately use the Spatie\Emoji\Emoji class in your application code. It is a self-contained utility that fits alongside Blade, Eloquent, and Form Requests.
- Does spatie/emoji work with Laravel 10, 11, and 12?
- Yes. spatie/emoji is framework-agnostic and does not depend on Laravel internals, so it works with any Laravel version that supports your PHP runtime. The 4.2.0 release does not add Laravel-specific requirements. You only need Composer and a PHP version compatible with the package.
- Should I use Emoji::grinningFace() or Emoji::CHARACTER_GRINNING_FACE?
- Both return the same emoji character. The CHARACTER_* constants are useful when your IDE or font cannot render emoji literals, while the camelCase methods provide a shorter, more readable call. Many teams standardize on one style and wrap it behind their own helper so generated names are easy to change later.
- How do I get an array of all emoji with spatie/emoji?
- Call Emoji::all() to get an array containing the full bundled emoji set. Be aware that this loads roughly 3,000+ emoji into memory, so avoid calling it on every request in hot paths. Cache the result with a version-suffixed cache key, especially after upgrading the package, so you do not keep serving the old set.
- How do I get a country flag emoji from an ISO 3166 Alpha2 code?
- spatie/emoji provides country flag helpers such as countryFlag() and flagsFor* methods that map ISO 3166 Alpha2 codes to flag emoji. Use the Alpha2 code for the country you need, for example a two-letter code like BE or US, and the package returns the corresponding flag character. Flag rendering can vary by platform, so test Windows, macOS, iOS, and Android if flags are user-facing.
- Can I use spatie/emoji in Blade templates?
- Yes. You can output emoji via the Emoji class in Blade expressions or use the package's @emoji and @emojiList directives. These directives are unaffected by the 4.2.0 Unicode update. If you hardcoded any renamed flag names in Blade views, update those references as part of the upgrade.
- How do I validate emoji input in Laravel with spatie/emoji?
- The package includes an EmojiValidator rule that you can apply to request fields or form requests. Its behavior is unchanged in 4.2.0. When adding newer emoji, sanity-check modifier sequences such as skin-tone variants for thumb signs against your validation rules and moderation filters.
- Does spatie/emoji parse shortcodes like :smile: into emoji?
- No. spatie/emoji focuses on named constants, camelCase methods, and country flag helpers; it does not convert shortcode syntax such as :smile: into 😊. If you need shortcode parsing, you must add custom regex logic or a separate parser. This is a common gap to plan for in chat or comment features.
- What changed in spatie/emoji 4.2.0 and do I need to update renamed emoji methods?
- Version 4.2.0 upgrades the bundled dataset from Unicode 15.1 to Unicode 18.0 and adds 19 new emoji, including skin-tone variants for the leftwards and rightwards thumb sign. Three flag emoji were renamed upstream, so generated methods and CHARACTER_* constants changed names while deprecated aliases remain for now. Grep your app, Blade views, tests, and seeders for the old flag names and plan to remove them before a future 5.0 release.
- Is spatie/emoji maintained and what alternatives should I consider?
- spatie/emoji is an MIT-licensed Spatie package with tests and is used widely in the PHP community, but generated names track Unicode and can change between minor releases. Wrap calls behind your own EmojiCatalog or App\Support\Emoji facade so renames are a one-file change. Alternatives include custom emoji maps or dedicated shortcode parsers if you need :smile: conversion; for named emoji and country flags, spatie/emoji remains a lightweight choice.