Integrating Emoji Support in Laravel Using the Laravel‑Emoji Package
This article explains how to add Unicode emoji rendering to a Laravel application by installing the Laravel‑Emoji extension, configuring Composer, registering the service provider and alias, defining a route, and using the Emoji class in a controller to convert aliases, names, and Unicode codes into emoji graphics.
With the rapid growth of the Internet, text alone is no longer sufficient for expressive communication, and emojis have become essential in web and app content. PHP 7 offers better Unicode support, making it easier to display emojis in Laravel projects.
First, install Laravel (refer to the official Laravel documentation) and then add the unicodeveloper/laravel-emoji": "1.0.* package to the require section of composer.json :
"unicodeveloper/laravel-emoji": "1.0.*",
"php": "^7.1.3",
"fideloper/proxy": "^4.0",
"laravel/framework": "5.8.*",
"laravel/tinker": "^1.0",
"jacobcyl/ali-oss-storage": "^2.1",
"unicodeveloper/laravel-emoji": "1.0.*"Run composer update to install the package. After installation, register the service provider and alias in config/app.php :
<?php
'providers' => [
// ... other providers
Unicodeveloper\Emoji\EmojiServiceProvider::class,
],
'aliases' => [
// ... other aliases
'Emoji' => Unicodeveloper\Emoji\Facades\Emoji::class,
];Define a route for testing:
Route::get('/index/index', '\App\Http\Controllers\Index\IndexController@index');Create the controller and use the Emoji class to convert emoji aliases, names, and Unicode codes:
<?php
namespace App\Http\Controllers\Index;
use App\Http\Controllers\Controller;
use Unicodeveloper\Emoji\Emoji;
class IndexController extends Controller {
public function index() {
$em = new Emoji();
$res = $em->findByAlias('laughing');
$res1 = $em->findByName('grinning');
$res2 = $em->findByUnicode("\u{1F617}");
print_r($res);
print_r($res1);
print_r($res2);
exit;
}
}Visiting the defined route displays the converted emoji output. For more emoji resources, refer to the official Unicode emoji list at unicode.org/emoji/charts/full-emoji-list.html .
The article also provides additional Laravel reference links such as Artisan, Composer, Session, and Cookie cheat sheets.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.