mlsolutions/nova-font-awesome-field
A Laravel Nova field for selecting Font Awesome icons in your admin forms, storing the chosen icon class on your model. Drop it into resources for menus, categories, or any record that needs an icon.
Install the package and confirm the field class name from its README or vendor/mlsolutions/nova-font-awesome-field/src:
composer require mlsolutions/nova-font-awesome-field
Publish any package config/assets using the provider or tag documented by the package, then clear caches:
php artisan vendor:publish --provider="MlSolutions\NovaFontAwesomeField\FontAwesomeFieldServiceProvider"
php artisan config:clear
php artisan view:clear
Add a string column to the model’s table if you do not already have one:
$table->string('icon')->nullable();
The first practical use case is replacing a free-text “icon class” input on a Nova resource — for example a Category, MenuItem, or NavigationLink resource:
use MlSolutions\NovaFontAwesomeField\FontAwesome;
public function fields(NovaRequest $request): array
{
return [
FontAwesome::make('Icon')
->rules('nullable', 'string', 'max:255')
->help('Choose the Font Awesome icon used in the front end.'),
];
}
Store the full CSS class string, such as fa-solid fa-house or fas fa-user, so the value can be rendered directly in Blade without a lookup table.
Look first at:
vendor/mlsolutions/nova-font-awesome-field/src to see which Font Awesome versions/styles it supports.Basic resource field
Use the picker as a normal Nova field and keep the database column as a nullable string:
FontAwesome::make('Icon', 'icon')
->rules('nullable', 'string', 'max:255')
->hideFromIndex();
If the field supports configuration methods for icon style or version, set them explicitly rather than relying on package defaults:
FontAwesome::make('Icon')
->style('solid') // confirm supported methods in the package source
->version('6'); // confirm supported methods in the package source
Display the icon on index/detail
Because the stored value is just a CSS class string, render it yourself for consistent presentation:
FontAwesome::make('Icon')
->displayUsing(function ($value) {
return $value
? "<i class=\"{$value}\" aria-hidden=\"true\"></i> <span>{$value}</span>"
: '—';
})
->asHtml()
->onlyOnIndex();
For detail views, either render the icon with a custom displayUsing, or show the raw class string and let the front end handle rendering.
Normalize before saving
Icon values are easy to enter inconsistently. Normalize on fill so production data stays predictable:
FontAwesome::make('Icon')
->fillUsing(function ($request, $model, $attribute, $requestAttribute) {
$value = $request->input($requestAttribute);
$model->{$attribute} = $value ? trim($value) : null;
});
If the field emits only an icon name rather than a full class, convert it to a canonical class in fillUsing and keep the full class string in the database.
Restrict choices to a known set
If the package exposes an options/config list, narrow it to the families and styles your site loads. This avoids invalid values and makes the picker faster:
// Example shape only — confirm the actual config keys.
'styles' => ['solid', 'regular', 'brands'],
'version' => 6,
For stricter control, validate against an allowlist:
use Illuminate\Validation\Rule;
FontAwesome::make('Icon')
->rules([
'nullable',
'string',
Rule::in(config('app.allowed_icons', [])),
]);
Front-end rendering
In Blade, use the stored class directly:
@if ($category->icon)
<i class="{{ $category->icon }}" aria-hidden="true"></i>
@endif
Keep the Font Awesome CSS version in the front end aligned with the version used by the Nova picker.
Reuse across resources
If many resources need the same picker, wrap it in a helper or trait:
protected function iconField(string $label = 'Icon'): FontAwesome
{
return FontAwesome::make($label)
->rules('nullable', 'string', 'max:255')
->help('Select a Font Awesome icon.');
}
vendor source before rolling it out.fa-solid/fas naming differs between Font Awesome 5 and 6) and that brand icons use the correct family.asHtml() is an XSS vector if users can submit arbitrary values. Constrain the picker and validate against a known list.null or '', and normalize in fillUsing so queries and Blade conditionals behave consistently.hideFromIndex() and show the rendered icon or a short label instead.php artisan config:clear and, in production, rebuild any cached config. Nova asset caching can also make the picker appear unchanged after an upgrade.How can I help you explore Laravel packages today?