spatie/emoji
Work with emoji in PHP without relying on your IDE/font. Use the Spatie\Emoji\Emoji class to access emoji as constants or friendly camelCase methods like Emoji::grinningFace(), or fetch all emojis via Emoji::all().
countryFlag() method adds value for localization-heavy projects (e.g., travel apps, e-commerce).composer require spatie/emoji.@emoji, @emojiList) reduce frontend boilerplate. Works out-of-the-box with Tailwind CSS, Bootstrap, or custom CSS for styling.EmojiValidator class integrates natively with Laravel’s validation pipeline, enabling rules like:
'comment' => 'required|string|emoji',
This is a low-effort win for moderation systems (e.g., blocking malicious emoji sequences).🇧🇪) may render as separate characters in some environments.Emoji::all() method loads ~3,000 emojis into memory. For high-traffic APIs or CLI tools, consider lazy-loading or caching the emoji set.^4.1.2) during initial rollout.:smile: → 😊 conversion out-of-the-box. Requires custom logic (e.g., a regex replacer) if this is a priority.Emoji::all() memory usage.@emoji('grinningFace') <!-- Outputs: 😃 -->
@emojiList('flags') <!-- Outputs: 🇺🇸🇬🇧🇯🇵 -->
use Spatie\Emoji\Casts\Emoji;
class Comment extends Model {
protected $casts = [
'emoji' => Emoji::class,
];
}
$request->validate([
'reaction' => 'required|emoji',
]);
emoji { font-size: 1.2em; }).if (featureEnabled('emojis')) {
echo Emoji::grinningFace();
}
@emoji).😊 in a VARCHAR field).Emoji class is stateless and thread-safe. Cache Emoji::all() if performance is critical:
$emojis = Cache::remember('all_emojis', now()->addHours(1), fn() => Emoji::all());
update).try {
echo Emoji::unknownEmoji(); // Outputs: 🤷
} catch (\InvalidArgumentException $e) {
echo '❌'; // Fallback
}
aria-label to emoji buttons.👍 (Like)).Emoji::all() loads ~3,000 emojis (~100KB). For high-traffic APIs, cache the result or lazy-load emojis as needed.| Failure Scenario | Impact | **Mitigation
How can I help you explore Laravel packages today?