Installation:
composer require hasnayeen/themes
php artisan vendor:publish --tag="themes-assets"
php artisan vendor:publish --tag="themes-migrations"
php artisan migrate
First Use Case:
Settings > Themes).Where to Look First:
config/themes.php (published via vendor:publish).
resources/views/vendor/filament-themes/ (customize via publishing).database/migrations/[timestamp]_create_theme_preferences_table.php (if using user-specific themes).Global vs. User-Specific Themes:
config/themes.php under default_theme.
'default_theme' => 'light',
theme_preferences table (requires migrations).
// Access user theme in Filament widgets/panels:
$userTheme = auth()->user()->theme_preferences->theme ?? config('themes.default_theme');
Customizing Themes:
ThemesWidget to adjust colors for the selected theme.
// Override default colors in config:
'themes' => [
'dark' => [
'colors' => [
'primary' => '#3b82f6',
'danger' => '#ef4444',
],
],
],
'themes' => [
'custom' => [
'path' => 'path/to/custom-theme-folder',
'colors' => ['primary' => '#10b981'],
],
],
Integration with Filament Panels:
return Panel::make()
->id('admin')
->path('admin')
->theme(fn () => auth()->user()->theme_preferences->theme ?? 'light')
->discoverResources(in: app_path('Http/Controllers/Admin'))
->discoverPages(in: app_path('Http/Controllers/Admin/Pages'));
ThemesWidget in your Filament dashboard:
use Hasnayeen\Themes\Widgets\ThemesWidget;
public function getWidgets(): array
{
return [
ThemesWidget::class,
];
}
Asset Customization:
php artisan vendor:publish --tag="themes-assets" --force
resources/views/vendor/filament-themes/components/theme-selector.blade.php to change the UI.Conditional Theme Application:
$theme = auth()->user()->is_admin ? 'admin' : (now()->hour < 6 ? 'dark' : 'light');
Panel::make()->theme(fn () => $theme);
Theme Events:
// Example: Log theme changes
event(new \Hasnayeen\Themes\Events\ThemeChanged($oldTheme, $newTheme));
Dark Mode Detection:
// In your Filament panel's JS:
document.documentElement.classList.toggle('dark', window.matchMedia('(prefers-color-scheme: dark)').matches);
Asset Loading Issues:
php artisan view:clear
php artisan cache:clear
resources/views/vendor/filament-themes for overrides.Migration Conflicts:
php artisan migrate fails due to column conflicts.theme_preferences table migration if extending it:
Schema::table('theme_preferences', function (Blueprint $table) {
$table->string('custom_color')->nullable()->after('theme');
});
Theme Not Persisting:
theme_preferences table is populated and the theme() method in Panel uses:
->theme(fn () => auth()->check() ? auth()->user()->theme_preferences->theme : config('themes.default_theme'))
Tailwind CSS Conflicts:
!important sparingly:
.filament-theme-dark .bg-primary {
@apply bg-[#3b82f6];
}
Log Theme Values:
use Filament\Widgets\Widget;
class DebugThemeWidget extends Widget
{
protected static string $view = 'filament-themes::debug-theme';
}
{{ dd(auth()->user()->theme_preferences->toArray()) }}.Check Published Config:
config/themes.php matches your expectations:
php artisan config:clear
php artisan config:cache
Inspect Network Requests:
filament-themes.css or filament-themes.js.Add New Themes:
ThemesServiceProvider or create a custom provider:
// app/Providers/ThemesServiceProvider.php
public function register()
{
$this->app->singleton(ThemesManager::class, function () {
$manager = new ThemesManager();
$manager->addTheme('my-theme', [
'path' => 'path/to/theme',
'colors' => ['primary' => '#8b5cf6'],
]);
return $manager;
});
}
Custom Theme UI:
php artisan vendor:publish --tag="themes-views" --force
resources/views/vendor/filament-themes/components/theme-selector.blade.php.API for Themes:
use Hasnayeen\Themes\Contracts\Theme;
public static function getRelations(): array
{
return [
'theme' => Theme::class,
];
}
Theme Presets:
// Migration:
Schema::create('theme_presets', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->json('colors');
$table->timestamps();
});
How can I help you explore Laravel packages today?