PHP code example of marshmallow / nova-fontawesome
1. Go to this page and download the library: Download marshmallow/nova-fontawesome library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
marshmallow / nova-fontawesome example snippets
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
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'),
];
}
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 (' => 0.3, // 0-1, lower = stricter matching
],
// Auto-convert legacy FA5 classes to modern format when saving
'convert_legacy_format' => true,
];
public function getIconHtmlAttribute(): string
{
if (!$this->icon) {
return '';
}
return sprintf('<i class="%s"></i>', e($this->icon));
}