PHP code example of alizharb / filament-game-icons

1. Go to this page and download the library: Download alizharb/filament-game-icons 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/ */

    

alizharb / filament-game-icons example snippets


use Alizharb\FilamentGameIcons\Enums\GameIcons;
use Filament\Actions\Action;

Action::make('attack')
    ->icon(GameIcons::Sword)
    ->label('Attack with Sword')
    ->color('danger');

use Alizharb\FilamentGameIcons\Enums\GameIcons;
use Filament\Actions\Action;

// Basic action with icon
Action::make('attack')
    ->icon(GameIcons::Sword)
    ->color('danger')
    ->nd')->icon(GameIcons::Shield),
        Action::make('cast_spell')->icon(GameIcons::MagicSwirl),
    ]);

use Filament\Forms\Components\{Select, Toggle, Radio, Checkbox};

// Enhanced select with searchable icons
Select::make('character_class')
    ->options(GameIcons::getCharactersArray())
    ->searchable()
    ->native(false)
    ->allowHtml()
    ->placeholder('Choose your character class...');

// Toggle with custom icons
Toggle::make('is_magical')
    ->onIcon(GameIcons::MagicSwirl)
    ->offIcon(GameIcons::Sword)
    ->onColor('primary')
    ->offColor('gray');

// Radio with descriptions
Radio::make('weapon_preference')
    ->options(GameIcons::getWeaponsArray())
    ->descriptions([
        GameIcons::Sword->value => 'Balanced attack and defense',
        GameIcons::BowArrow->value => 'Long-range precision strikes',
        GameIcons::MagicSwirl->value => 'Powerful elemental damage',
    ]);

use Filament\Tables\Columns\{IconColumn, TextColumn};

// Dynamic status icons
IconColumn::make('player_status')
    ->icon(fn ($record): string => match ($record->status) {
        'online' => GameIcons::Person->value,
        'in_battle' => GameIcons::CrossedSwords->value,
        'resting' => GameIcons::Sleep->value,
        'offline' => GameIcons::Skull->value,
    })
    ->color(fn ($record): string => match ($record->status) {
        'online' => 'success',
        'in_battle' => 'warning',
        'resting' => 'info',
        'offline' => 'gray',
    })
    ->tooltip(fn ($record): string => "Player is {$record->status}");

// Equipment column with multiple icons
TextColumn::make('equipment')
    ->formatStateUsing(function ($record): string {
        $icons = [];
        if ($record->weapon) $icons[] = GameIcons::Sword->value;
        if ($record->armor) $icons[] = GameIcons::Armor->value;
        if ($record->magic_item) $icons[] = GameIcons::MagicSwirl->value;

        return view('components.icon-list', compact('icons'))->render();
    });

use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;

class GameDashboardWidget extends BaseWidget
{
    protected function getStats(): array
    {
        return [
            Stat::make('👥 Active Players', $this->getActivePlayers())
                ->description('Currently online')
                ->descriptionIcon(GameIcons::Person->value)
                ->chart([7, 2, 10, 3, 15, 4, 17])
                ->color('success'),

            Stat::make('⚔️ Battles Today', $this->getBattlesToday())
                ->description('32% increase from yesterday')
                ->descriptionIcon(GameIcons::CrossedSwords->value)
                ->color('warning'),

            Stat::make('🏆 Achievements', $this->getAchievements())
                ->description('Unlocked this week')
                ->descriptionIcon(GameIcons::Trophy->value)
                ->color('primary'),

            Stat::make('💰 Gold Earned', number_format($this->getGoldEarned()))
                ->description('Total server economy')
                ->descriptionIcon(GameIcons::GoldStack->value)
                ->color('warning'),
        ];
    }
}



namespace App\Filament\Resources;

use Alizharb\FilamentGameIcons\Enums\GameIcons;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;

class CharacterResource extends Resource
{
    protected static ?string $model = Character::class;
    protected static ?string $navigationIcon = 'gameicon-person';
    protected static ?string $navigationGroup = 'Game Management';

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\Section::make('Character Information')
                    ->icon(GameIcons::Person->value)
                    ->schema([
                        Forms\Components\TextInput::make('name')
                            ->:Person->value),

                        Forms\Components\Select::make('race')
                            ->options(GameIcons::getCreaturesArray())
                            ->searchable()
                            ->native(false)
                            ->prefixIcon(GameIcons::Dragon->value),
                    ]),

                Forms\Components\Section::make('Equipment & Stats')
                    ->icon(GameIcons::Sword->value)
                    ->schema([
                        Forms\Components\Select::make('primary_weapon')
                            ->options(GameIcons::getWeaponsArray())
                            ->searchable()
                            ->native(false)
                            ->prefixIcon(GameIcons::Sword->value),

                        Forms\Components\Select::make('armor_type')
                            ->options([
                                'light' => 'Light Armor',
                                'medium' => 'Medium Armor',
                                'heavy' => 'Heavy Armor',
                            ])
                            ->prefixIcon(GameIcons::Armor->value),

                        Forms\Components\Grid::make(3)
                            ->schema([
                                Forms\Components\TextInput::make('level')
                                    ->numeric()
                                    ->default(1)
                                    ->minValue(1)
                                    ->maxValue(100)
                                    ->prefixIcon(GameIcons::Trophy->value),

                                Forms\Components\TextInput::make('health')
                                    ->numeric()
                                    ->default(100)
                                    ->minValue(0)
                                    ->prefixIcon(GameIcons::Heart->value),

                                Forms\Components\TextInput::make('mana')
                                    ->numeric()
                                    ->default(50)
                                    ->minValue(0)
                                    ->prefixIcon(GameIcons::MagicSwirl->value),
                            ]),
                    ]),

                Forms\Components\Section::make('Status & Abilities')
                    ->icon(GameIcons::Lightning->value)
                    ->schema([
                        Forms\Components\Toggle::make('is_alive')
                            ->default(true)
                            ->onIcon(GameIcons::Heart->value)
                            ->offIcon(GameIcons::Skull->value)
                            ->onColor('success')
                            ->offColor('danger'),

                        Forms\Components\CheckboxList::make('abilities')
                            ->options([
                                'stealth' => 'Stealth',
                                'magic_resistance' => 'Magic Resistance',
                                'critical_strike' => 'Critical Strike',
                                'healing' => 'Healing',
                                'fire_immunity' => 'Fire Immunity',
                            ])
                            ->columns(2),

                        Forms\Components\Textarea::make('backstory')
                            ->rows(4)
                            ->placeholder('Tell us about your character\'s history...')
                            ->columnSpanFull(),
                    ]),
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\ImageColumn::make('avatar')
                    ->circular()
                    ->defaultImageUrl(fn ($record) => 'https://ui-avatars.com/api/?name=' . urlencode($record->name)),

                Tables\Columns\TextColumn::make('name')
                    ->searchable()
                    ->sortable()
                    ->weight('bold'),

                Tables\Columns\IconColumn::make('class')
                    ->icon(fn (string $state): string => match ($state) {
                        'warrior' => GameIcons::Warrior->value,
                        'wizard' => GameIcons::Wizard->value,
                        'archer' => GameIcons::Archer->value,
                        'rogue' => GameIcons::Rogue->value,
                        'paladin' => GameIcons::Paladin->value,
                        'druid' => GameIcons::Druid->value,
                        default => GameIcons::Person->value,
                    })
                    ->color(fn (string $state): string => match ($state) {
                        'warrior' => 'danger',
                        'wizard' => 'info',
                        'archer' => 'success',
                        'rogue' => 'warning',
                        'paladin' => 'primary',
                        'druid' => 'success',
                        default => 'gray',
                    })
                    ->tooltip(fn ($record): string => ucfirst($record->class)),

                Tables\Columns\ProgressColumn::make('health')
                    ->getStateUsing(fn ($record): float => $record->health / $record->max_health * 100)
                    ->color('success')
                    ->alignment('center'),

                Tables\Columns\TextColumn::make('level')
                    ->badge()
                    ->color('warning')
                    ->sortable(),

                Tables\Columns\IconColumn::make('is_alive')
                    ->boolean()
                    ->trueIcon(GameIcons::Heart->value)
                    ->falseIcon(GameIcons::Skull->value)
                    ->trueColor('success')
                    ->falseColor('danger'),

                Tables\Columns\TextColumn::make('created_at')
                    ->dateTime()
                    ->sortable()
                    ->toggleable(isToggledHiddenByDefault: true),
            ])
            ->defaultSort('level', 'desc')
            ->filters([
                Tables\Filters\SelectFilter::make('class')
                    ->options([
                        'warrior' => 'Warrior',
                        'wizard' => 'Wizard',
                        'archer' => 'Archer',
                        'rogue' => 'Rogue',
                        'paladin' => 'Paladin',
                        'druid' => 'Druid',
                    ])
                    ->indicator('Character Class'),

                Tables\Filters\Filter::make('alive_only')
                    ->label('Alive Characters Only')
                    ->query(fn ($query) => $query->where('is_alive', true))
                    ->default(),
            ])
            ->actions([
                Tables\Actions\ActionGroup::make([
                    Tables\Actions\ViewAction::make()
                        ->icon(GameIcons::Eye->value),

                    Tables\Actions\EditAction::make()
                        ->icon(GameIcons::Scroll->value),

                    Tables\Actions\Action::make('heal')
                        ->icon(GameIcons::HealingPotion->value)
                        ->color('success')
                        ->action(fn ($record) => $record->heal())
                        ->visible(fn ($record) => $record->health < $record->max_health),

                    Tables\Actions\Action::make('revive')
                        ->icon(GameIcons::Resurrection->value)
                        ->color('warning')
                        ->

use Filament\Widgets\ChartWidget;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;

class GameStatsWidget extends BaseWidget
{
    protected function getStats(): array
    {
        return [
            Stat::make('🎮 Active Players', $this->getActivePlayers())
                ->description('Currently online')
                ->descriptionIcon(GameIcons::Person->value)
                ->chart($this->getPlayerChart())
                ->color('success')
                ->extraAttributes(['class' => 'game-stat-card']),

            Stat::make('⚔️ Battles This Hour', $this->getBattlesThisHour())
                ->description('Peak combat activity')
                ->descriptionIcon(GameIcons::CrossedSwords->value)
                ->chart($this->getBattleChart())
                ->color('danger'),

            Stat::make('🏆 Achievements Unlocked', $this->getAchievementsToday())
                ->description('New achievements today')
                ->descriptionIcon(GameIcons::Trophy->value)
                ->color('warning'),

            Stat::make('💰 Server Economy', '$' . number_format($this->getTotalGold()))
                ->description('Total gold in circulation')
                ->descriptionIcon(GameIcons::GoldStack->value)
                ->color('primary'),
        ];
    }
}

class PlayerActivityChart extends ChartWidget
{
    protected static ?string $heading = 'Player Activity';
    protected static string $color = 'info';
    protected static ?string $icon = 'gameicon-person';

    protected function getData(): array
    {
        return [
            'datasets' => [
                [
                    'label' => 'Online Players',
                    'data' => [65, 78, 66, 44, 56, 67, 75],
                    'backgroundColor' => 'rgba(59, 130, 246, 0.1)',
                    'borderColor' => 'rgb(59, 130, 246)',
                ],
            ],
            'labels' => ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
        ];
    }

    protected function getType(): string
    {
        return 'line';
    }
}

// Core functionality
GameIcons::Sword->getLabel();           // "Sword"
GameIcons::Sword->value;                // "gameicon-sword"
GameIcons::toSelectArray();             // All icons as options
GameIcons::search('magic');             // Search icons
GameIcons::random();                    // Get random icon

// Category methods
GameIcons::getWeapons();                // Array of weapon icons
GameIcons::getMagic();                  // Array of magic icons
GameIcons::getCharacters();             // Array of character icons
GameIcons::getCreatures();              // Array of creature icons
GameIcons::getDice();                   // Array of dice icons

// Category arrays (for selects)
GameIcons::getWeaponsArray();           // ['gameicon-sword' => 'Sword', ...]
GameIcons::getMagicArray();             // ['gameicon-magic-swirl' => 'Magic Swirl', ...]
GameIcons::getCharactersArray();        // ['gameicon-wizard' => 'Wizard', ...]

// Utility methods
GameIcons::make('custom-icon');         // "gameicon-custom-icon"
GameIcons::count();                     // Total number of icons
GameIcons::categories();                // Available categories

// Advanced search
$results = GameIcons::search('sword', [
    'category' => 'weapons',
    'limit' => 10,
    'exact' => false
]);

// Filter by multiple criteria
$filtered = GameIcons::filter([
    'categories' => ['weapons', 'magic'],
    'exclude' => ['skull', 'death'],
    '

// In your AppServiceProvider boot() method
use Filament\Support\Facades\FilamentIcon;
use Filament\View\PanelsIconAlias;
use Alizharb\FilamentGameIcons\Enums\GameIcons;

public function boot(): void
{
    FilamentIcon::register([
        // Navigation
        PanelsIconAlias::PANELS_SIDEBAR_COLLAPSE_BUTTON => GameIcons::Menu->value,
        PanelsIconAlias::PANELS_SIDEBAR_EXPAND_BUTTON => GameIcons::Menu->value,

        // Actions
        PanelsIconAlias::ACTIONS_CREATE_ACTION => GameIcons::Plus->value,
        PanelsIconAlias::ACTIONS_EDIT_ACTION => GameIcons::Scroll->value,
        PanelsIconAlias::ACTIONS_DELETE_ACTION => GameIcons::Skull->value,
        PanelsIconAlias::ACTIONS_VIEW_ACTION => GameIcons::Eye->value,

        // Tables
        PanelsIconAlias::TABLES_SEARCH_FIELD => GameIcons::Search->value,
        PanelsIconAlias::TABLES_FILTER => GameIcons::Filter->value,

        // Global
        PanelsIconAlias::GLOBAL_SEARCH_FIELD => GameIcons::Search->value,
    ]);
}

// RPG character creation helpers
$characterIcons = GameIcons::forRPGClasses();
$weaponsByType = GameIcons::weaponsByType();
$spellsBySchool = GameIcons::spellsBySchool();

// Board game helpers
$diceSet = GameIcons::getStandardDiceSet(); // D4, D6, D8, D10, D12, D20
$cardSuits = GameIcons::getCardSuits();
$gamepieces = GameIcons::getGamePieces();

// Automatic dark mode adaptation
IconColumn::make('status')
    ->icon(GameIcons::Heart->value)
    ->color('success')
    ->extraAttributes([
        'class' => 'dark:filter dark:brightness-110'
    ]);

// Create themed icon sets
class ThemeManager
{
    public static function getFireTheme(): array
    {
        return [
            'primary' => GameIcons::Fire->value,
            'secondary' => GameIcons::Explosion->value,
            'accent' => GameIcons::Lightning->value,
            'background' => GameIcons::Flame->value,
        ];
    }

    public static function getIceTheme(): array
    {
        return [
            'primary' => GameIcons::Ice->value,
            'secondary' => GameIcons::Snowflake->value,
            'accent' => GameIcons::Crystal->value,
            'background' => GameIcons::Blizzard->value,
        ];
    }
}



use Alizharb\FilamentGameIcons\Enums\GameIcons;
use Alizharb\FilamentGameIcons\Tests\TestCase;

class GameIconsTest extends TestCase
{
    /** @test */
    public function it_can_get_icon_labels(): void
    {
        expect(GameIcons::Sword->getLabel())->toBe('Sword');
        expect(GameIcons::MagicSwirl->getLabel())->toBe('Magic Swirl');
    }

    /** @test */
    public function it_can_search_icons(): void
    {
        $results = GameIcons::search('sword');

        expect($results)->toContain(GameIcons::Sword);
        expect($results)->toContain(GameIcons::CrossedSwords);
    }

    /** @test */
    public function it_can_get_category_arrays(): void
    {
        $weapons = GameIcons::getWeaponsArray();

        expect($weapons)->toBeArray();
        expect($weapons)->toHaveKey(GameIcons::Sword->value);
        expect($weapons[GameIcons::Sword->value])->toBe('Sword');
    }
}

// Spatie Media Library
use Spatie\MediaLibrary\HasMedia;

class Character extends Model implements HasMedia
{
    public function getAvatarIconAttribute(): string
    {
        return $this->class ? GameIcons::getClassIcon($this->class) : GameIcons::Person->value;
    }
}

// Before (Heroicons)
Action::make('delete')
    ->icon('heroicon-o-trash')
    ->color('danger');

// After (Game Icons)
Action::make('delete')
    ->icon(GameIcons::Skull)
    ->color('danger');

// In your AppServiceProvider
public function boot(): void
{
    // Enable icon caching
    GameIcons::enableCaching();

    // Preload frequently used categories
    GameIcons::preload(['weapons', 'magic', 'characters']);
}

// ✅ DO: Use enum constants for type safety
Action::make('attack')->icon(GameIcons::Sword);

// ❌ DON'T: Use magic strings
Action::make('attack')->icon('gameicon-sword');

// ✅ DO: Group related icons
$combatIcons = [
    GameIcons::Sword,
    GameIcons::Shield,
    GameIcons::Armor,
];

// ✅ DO: Use descriptive variable names
$healingSpellIcon = GameIcons::HealingPotion;
$attackSpellIcon = GameIcons::Lightning;

// Cache frequently used icon arrays
class IconCache
{
    private static array $weaponCache = [];

    public static function getWeapons(): array
    {
        return self::$weaponCache ??= GameIcons::getWeaponsArray();
    }
}

// Preload icons for better performance
public function boot(): void
{
    GameIcons::preload(['weapons', 'magic', 'characters']);
}
bash
php artisan filament:assets
bash
php artisan vendor:publish --tag=filament-game-icons-styles
bash
# Clear caches
php artisan cache:clear
php artisan view:clear

# Re-register assets
php artisan filament:assets

# Check if blade-game-icons is installed
composer show codeat3/blade-game-icons
bash
# Generate IDE helper files
composer dump-autoload

# For PhpStorm users
php artisan ide-helper:generate
php artisan ide-helper:models