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

NovaFontAwesome::make('Icon')
    ->families(['classic', 'brands', 'duotone', 'sharp'])

// Only free icons (default)
NovaFontAwesome::make('Icon')
    ->freeOnly()

// Include Pro icons (

NovaFontAwesome::make('Icon')
    ->kitId('abc123def')

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')

NovaFontAwesome::make('Icon')
    ->defaultIcon('far', 'check-circle')
    ->persistDefaultIcon()

NovaFontAwesome::make('Icon')
    ->only([
        'facebook',
        'twitch',
        'twitter',
    ])

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'),
    ];
}

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));
}
bash
php artisan vendor:publish --tag=nova-fontawesome-config
bash
php artisan vendor:publish --tag=nova-fontawesome-lang
bash
php artisan cache:clear
bash
composer analyse