A Font Awesome 6/7 Field for Laravel Nova 5
marshmallow/nova-fontawesome is a Laravel package for a font awesome 6/7 field for laravel nova 5.
It currently has 7 GitHub stars and 40.186 downloads on Packagist (latest version v3.1.0).
Install it with composer require marshmallow/nova-fontawesome.
Discover more Laravel packages by marshmallow
or browse all Laravel packages to compare alternatives.
Last updated
A Laravel Nova field for selecting Font Awesome icons using the Font Awesome GraphQL API. This package loads icons on-demand via API calls, meaning you don't need to bundle all 30,000+ icons in your package.
[!important] This package was originally forked from mdixon18/fontawesome. Since we were making many opinionated changes, we decided to continue development in our own version rather than submitting pull requests that might not benefit all users of the original package. You're welcome to use this package, we're actively maintaining it. If you encounter any issues, please don't hesitate to reach out.
Note: For Nova 4 support, use version 1.x:
composer require marshmallow/nova-fontawesome:^1.0
composer require marshmallow/nova-fontawesome
The package needs Font Awesome CSS to render icons. Choose one of these options:
Option A: Self-hosted (Recommended for Pro users)
css and webfonts folders to public/vendor/fontawesome/.env:
FONTAWESOME_CSS_STRATEGY=self-hosted
FONTAWESOME_CSS_PATH=/vendor/fontawesome/css/all.min.css
Option B: Font Awesome Kit (Easiest for Pro)
.env:
FONTAWESOME_CSS_STRATEGY=kit
FONTAWESOME_KIT_ID=abc123def
Option C: CDN (Free icons only)
No setup needed - this is the fallback if no other strategy is configured:
FONTAWESOME_CSS_STRATEGY=cdn
FONTAWESOME_CDN_VERSION=7.0.1
php artisan vendor:publish --tag=nova-fontawesome-config
You can also publish the translation files if you want to customise the UI strings:
php artisan vendor:publish --tag=nova-fontawesome-lang
php artisan cache:clear
That's it! The package uses the Font Awesome GraphQL API, so you don't need to manually download icon data.
The package supports three CSS loading strategies (in order of priority):
Download Font Awesome CSS files and host them on your server:
public/vendor/fontawesome/.env:FONTAWESOME_CSS_STRATEGY=self-hosted
FONTAWESOME_CSS_PATH=/vendor/fontawesome/css/all.min.css
Directory structure:
public/
โโโ vendor/
โโโ fontawesome/
โโโ css/
โ โโโ all.min.css
โโโ webfonts/
โโโ (font files)
Use your Font Awesome Kit for automatic Pro CSS loading:
FONTAWESOME_CSS_STRATEGY=kit
FONTAWESOME_KIT_ID=abc123def
Get your Kit ID from fontawesome.com/kits
Load free icons from CDN (default fallback):
FONTAWESOME_CSS_STRATEGY=cdn
FONTAWESOME_CDN_VERSION=7.0.1
use Marshmallow\NovaFontAwesome\NovaFontAwesome;
public function fields(NovaRequest $request): array
{
return [
ID::make()->sortable(),
NovaFontAwesome::make('Icon'),
];
}
NovaFontAwesome::make('Icon')
->version('6.x') // or '7.x', or specific like '6.5.1'
NovaFontAwesome::make('Icon')
->styles(['solid', 'brands']) // Only show solid and brand icons
Available styles: solid, regular, light, thin, duotone, brands
NovaFontAwesome::make('Icon')
->families(['classic', 'brands', 'duotone', 'sharp'])
Available families: classic, brands, duotone, sharp, sharp-duotone
Note: Duotone, Sharp, and Sharp-Duotone require Font Awesome Pro.
// Only free icons (default)
NovaFontAwesome::make('Icon')
->freeOnly()
// Include Pro icons (requires FA Pro subscription and API token)
NovaFontAwesome::make('Icon')
->includePro()
Load Pro CSS using your Font Awesome Kit:
NovaFontAwesome::make('Icon')
->kitId('abc123def')
Or use a custom Pro CSS URL:
NovaFontAwesome::make('Icon')
->proCssUrl('https://pro.fontawesome.com/releases/v6.5.0/css/all.css')
NovaFontAwesome::make('Icon')
->nullable()
NovaFontAwesome::make('Icon')
->addButtonText('Click Me!')
NovaFontAwesome::make('Icon')
->maxResults(100) // Icons per page for infinite scroll
NovaFontAwesome::make('Icon')
->minSearchLength(3) // Require 3 characters before searching
NovaFontAwesome::make('Icon')
->defaultIcon('far', 'check-circle')
If you want to persist the default icon (when they press clear it brings back the default so it can't be empty):
NovaFontAwesome::make('Icon')
->defaultIcon('far', 'check-circle')
->persistDefaultIcon()
NovaFontAwesome::make('Icon')
->only([
'facebook',
'twitch',
'twitter',
])
Enable or disable the local fuzzy search fallback:
NovaFontAwesome::make('Icon')
->fuzzySearch(true) // enabled by default
->fuzzySearchThreshold(0.3) // 0-1, lower = stricter matching
use Marshmallow\NovaFontAwesome\NovaFontAwesome;
public function fields(NovaRequest $request): array
{
return [
ID::make()->sortable(),
Text::make('Name'),
NovaFontAwesome::make('Icon')
->version('6.x')
->styles(['solid', 'regular', 'brands'])
->families(['classic', 'brands'])
->freeOnly()
->nullable()
->addButtonText('Choose an icon...')
->maxResults(100)
->minSearchLength(2)
->fuzzySearch(true)
->help('Select an icon to represent this item'),
];
}
The field stores icons in modern FA6/FA7 format:
"fa-solid fa-user"
"fa-regular fa-arrow-right"
"fa-brands fa-github"
"fa-duotone fa-solid fa-house"
"fa-sharp fa-solid fa-home"
The package automatically supports legacy FA5 shorthand classes for backwards compatibility:
| Legacy Format | Converts To |
|--------------|-------------|
| fas fa-home | fa-solid fa-home |
| far fa-user | fa-regular fa-user |
| fab fa-github | fa-brands fa-github |
| fal fa-star | fa-light fa-star |
| fat fa-circle | fa-thin fa-circle |
| fad fa-house | fa-duotone fa-solid fa-house |
When convert_legacy_format is enabled in config (default), legacy formats are automatically converted when saving.
This package uses the Font Awesome GraphQL API to:
The package registers these API routes:
GET /nova-vendor/nova-fontawesome/search - Search icons (with pagination)GET /nova-vendor/nova-fontawesome/icon/{name} - Get a specific iconGET /nova-vendor/nova-fontawesome/metadata - Get available families and stylesGET /nova-vendor/nova-fontawesome/config - Get CSS configurationGET /nova-vendor/nova-fontawesome/convert - Convert legacy class formatGET /nova-vendor/nova-fontawesome/debug - Troubleshooting endpointGET /nova-vendor/nova-fontawesome/fallback - Get fallback iconsAfter publishing the config file, you can modify config/nova-fontawesome.php:
return [
// Default Font Awesome version (6.x or 7.x, or a specific version like 7.0.1)
'version' => env('FONTAWESOME_VERSION', '7.0.1'),
// Cache duration in seconds (0 disables caching; default: 1 hour)
'cache_duration' => env('FONTAWESOME_CACHE_DURATION', 3600),
// Only show free icons by default
'free_only' => env('FONTAWESOME_FREE_ONLY', true),
// Default styles to show (free: solid, regular, brands)
'styles' => ['solid', 'regular', 'brands'],
// Available icon families (free: classic, brands)
'families' => ['classic', 'brands'],
// Maximum search results per page
'max_results' => env('FONTAWESOME_MAX_RESULTS', 100),
// Optional API token for authenticated requests (required for Pro icons)
'api_token' => env('FONTAWESOME_API_TOKEN'),
// CSS loading strategy
'css' => [
'strategy' => env('FONTAWESOME_CSS_STRATEGY', 'self-hosted'),
'path' => env('FONTAWESOME_CSS_PATH', '/vendor/fontawesome/css/all.min.css'),
'base_path' => env('FONTAWESOME_CSS_BASE_PATH', 'vendor/fontawesome/css'),
'webfonts_path' => env('FONTAWESOME_WEBFONTS_PATH', 'vendor/fontawesome/webfonts'),
'vite_path' => env('FONTAWESOME_VITE_PATH', 'resources/css/fontawesome'),
'kit_id' => env('FONTAWESOME_KIT_ID'),
'cdn_version' => env('FONTAWESOME_CDN_VERSION', '7.0.1'),
],
// Client-side fuzzy search settings
'fuzzy_search' => [
'enabled' => true,
'threshold' => 0.3, // 0-1, lower = stricter matching
],
// Auto-convert legacy FA5 classes to modern format when saving
'convert_legacy_format' => true,
];
Add these to your .env file to customize the configuration:
FONTAWESOME_VERSION=7.0.1
FONTAWESOME_CACHE_DURATION=3600
FONTAWESOME_FREE_ONLY=true
FONTAWESOME_MAX_RESULTS=100
# CSS Strategy (self-hosted, kit, or cdn)
FONTAWESOME_CSS_STRATEGY=self-hosted
FONTAWESOME_CSS_PATH=/vendor/fontawesome/css/all.min.css
# Only needed for Pro icons
FONTAWESOME_API_TOKEN=your-api-token-here
# Pro CSS loading options (pick one)
FONTAWESOME_KIT_ID=abc123def
To access Font Awesome Pro icons or improve API rate limits, you'll need an API token:
.env file:
FONTAWESOME_API_TOKEN=your-token-here
Note: API tokens are automatically exchanged for short-lived access tokens and cached for performance. The package handles token refresh automatically.
<!-- Direct usage -->
<i class="{{ $model->icon }}"></i>
<!-- Or with Font Awesome Kit -->
<i class="fa-solid fa-{{ $iconName }}"></i>
If rendering icons in your frontend (outside Nova), make sure Font Awesome CSS is loaded:
<!-- In your layout -->
<link rel="stylesheet" href="/vendor/fontawesome/css/all.min.css">
Or via your vite.config.js:
// Import in your JS
import '/public/vendor/fontawesome/css/all.min.css';
You can add a helper to your model:
public function getIconHtmlAttribute(): string
{
if (!$this->icon) {
return '';
}
return sprintf('<i class="%s"></i>', e($this->icon));
}
Visit /nova-vendor/nova-fontawesome/debug to check:
api.fontawesome.comphp artisan cache:clearpublic/vendor/fontawesome/Make sure you're using valid style names: solid, regular, light, thin, duotone, brands
.envcomposer.json requirementspackage.json - Vite replaces Laravel Mixnpm install && npm run buildcss section replaces pro_css)npm install
npm run dev # Development build
npm run build # Production build
npm run watch # Watch mode
composer test
composer lint # Fix code style
composer lint-check # Check without fixing
composer analyse
The MIT License (MIT). Please see License File for more information.
If you are reliant on this package in your production applications, consider sponsoring us! It is the best way to help us keep doing what we love to do: making great open source software.
Feel free to suggest changes, ask for new features or fix bugs yourself. We're sure there are still a lot of improvements that could be made, and we would be very happy to merge useful pull requests.
At Marshmallow we use a lot of open source software as part of our daily work. So when we have an opportunity to give something back, we're super excited!
We hope you will enjoy this small contribution from us and would love to hear from you if you find it useful in your projects. Follow us on Twitter for more updates!