codeat3/blade-google-material-design-icons
Use Google Material Design Icons as Blade components in Laravel. Powered by Blade Icons, supports configuration and icon caching for better performance. Browse included SVGs or preview icons on fonts.google.com. Compatible with PHP 7.4+ and Laravel 8+.
Installation
composer require codeat3/blade-google-material-design-icons
Add the service provider to config/app.php (if not auto-discovered):
'providers' => [
// ...
Codeat3\BladeGoogleMaterialDesignIcons\BladeGoogleMaterialDesignIconsServiceProvider::class,
],
Publish Config (Optional)
php artisan vendor:publish --provider="Codeat3\BladeGoogleMaterialDesignIcons\BladeGoogleMaterialDesignIconsServiceProvider"
Edit config/blade-google-material-design-icons.php to customize:
material-icons)First Usage In any Blade view:
@materialIcon('home')
Renders: <i class="material-icons">home</i>
This release ensures full compatibility with Laravel 13. No additional configuration is required for Laravel 13 projects. The package now leverages Laravel 13's auto-discovery features by default, eliminating the need to manually register the service provider in config/app.php for new Laravel 13 installations.
Use variables for dynamic icons:
@materialIcon($iconName, ['class' => 'text-blue-500'])
Example: Fetch icon name from DB/model:
$icon = $task->icon ?? 'check';
@materialIcon($icon, ['size' => 'large'])
Wrap in reusable components (e.g., resources/views/components/icon.blade.php):
@props(['name', 'size' => 'default'])
<i class="material-icons {{ $size }}">{{ $name }}</i>
Usage:
<x-icon name="favorite" size="large" />
Extend beyond material-icons:
'icon_sets' => [
'material-symbols' => 'https://fonts.googleapis.com/icon?family=Material+Symbols',
],
@materialIcon('home', [], 'material-symbols')
Pass HTML attributes directly:
@materialIcon('search', [
'aria-label' => 'Search',
'style' => 'color: #666; font-size: 24px;'
])
Combine with Blade conditionals:
@if($user->isAdmin)
@materialIcon('admin_panel_settings')
@else
@materialIcon('dashboard')
@endif
Missing CDN Fallback
'cdn_fallback' => asset('vendor/material-icons/material-icons.css'),
php artisan vendor:publish --tag=material-icons-assets
Caching Issues
php artisan view:clear
Icon Name Typos
<head> for injected <link> tags. Missing? Verify config icon_sets.Failed to load resource errors.Auto-Discovery
config/app.php unless you're using Laravel <13 or customizing the discovery behavior.Package Discovery
composer.json includes the package in the extra.laravel section:
"extra": {
"laravel": {
"providers": [
"Codeat3\\BladeGoogleMaterialDesignIcons\\BladeGoogleMaterialDesignIconsServiceProvider"
]
}
}
Custom Directives
Extend the package by creating a new directive (e.g., @materialIconOutline):
// app/Providers/BladeServiceProvider.php
Blade::directive('materialIconOutline', function ($icon) {
return "<?php echo '<i class=\"material-icons-outlined\">'.$icon.'</i>'; ?>";
});
Theme Support Dynamically switch themes (e.g., light/dark mode):
@materialIcon('brightness_4', [], 'material-symbols', ['class' => $theme === 'dark' ? 'text-white' : 'text-black'])
Local Overrides Override default icons via config:
'overrides' => [
'home' => 'home_outlined', // Replace default 'home' with outlined variant
],
<i class="material-icons"> with @materialIcon() in existing views.aria-hidden="true" or labels:
@materialIcon('search', ['aria-label' => 'Search products'])
?text= query in CDN URL (config option):
'cdn_url' => 'https://fonts.googleapis.com/icon?family=Material+Icons&text=home|search',
How can I help you explore Laravel packages today?