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