alizharb/filament-themes-manager
Filament-powered admin panel for managing themes in Laravel apps via qirolab/laravel-themer. Install themes from ZIP, GitHub, or local folders, clone and customize, preview safely, activate with one click, validate structure, and protect critical themes.
Installation:
composer require alizharb/filament-themes-manager
php artisan vendor:publish --tag=filament-themes-manager-config
Register Plugin in app/Providers/Filament/AdminPanelProvider.php:
public function panel(Panel $panel): Panel
{
return $panel->plugins([
FilamentThemesManagerPlugin::make(),
]);
}
Enable Preview Middleware (optional) in bootstrap/app.php:
->withMiddleware(function (Middleware $middleware) {
$middleware->web(append: [
\Alizharb\FilamentThemesManager\Http\Middleware\ThemePreviewMiddleware::class,
]);
})
Install a theme from GitHub:
php artisan theme:install username/repository --type=github --activate
Access the admin interface at System → Theme Manager in Filament to preview, activate, or manage themes.
Theme Installation:
php artisan theme:install username/repo --type=githubphp artisan theme:install /path/to/theme.zip --type=zipbase_path('themes') and auto-discover ('auto_discover' => true in config).Theme Management:
app(ThemeManagerService::class)->setActiveTheme('slug')./theme-preview/{slug} route or UI preview button.php artisan theme:clone source-slug new-slug "New Theme" --activate.Programmatic Access:
// Get all themes
$themes = app(ThemeManagerService::class)->getAllThemes();
// Check active theme
$activeTheme = Theme::active()->first();
// Install via API
$service->installThemeFromGitHub('username/repo');
theme.json with additional metadata (e.g., supports: ["dark-mode", "rtl"]).vite.config.js for optimized assets.ThemeActivated, ThemeInstalled) for custom logic:
// In EventServiceProvider
protected function shouldDispatch(): array
{
return [
ThemeActivated::class,
ThemeInstalled::class,
];
}
'widgets' => ['dashboard' => true]) to display theme stats on Filament dashboard.Theme Validation: Override ThemeValidator to add custom rules:
use Alizharb\FilamentThemesManager\Validators\ThemeValidator;
class CustomThemeValidator extends ThemeValidator
{
protected function rules(): array
{
return array_merge(parent::rules(), [
'theme.json' => ['required', 'json', function ($attribute, $value, $fail) {
if (!isset($value['custom_field'])) {
$fail('Custom field is required.');
}
}],
]);
}
}
Register in config/filament-themes-manager.php:
'validator' => CustomThemeValidator::class,
Preview Middleware: Extend middleware to add custom logic (e.g., redirect non-admin users):
public function handle($request, Closure $next)
{
if (!$request->user()->can('preview-themes')) {
abort(403);
}
return $next($request);
}
Permission Issues:
themes/ directory is writable (chmod -R 755 storage/framework/themes).storage/framework permissions or use storage_path('app/themes') in config.Preview Session Expiry:
'session_duration' (default: 3600s). Users may lose unsaved work.Asset Loading Failures:
theme.json paths (e.g., assets: ["css/app.css"] but file is css/app.scss) break asset compilation.theme.json and use php artisan theme:validate.Caching Conflicts:
'cache_duration' => 86400) may hide theme updates.php artisan cache:clear) or reduce duration in development.Middleware Registration:
ThemePreviewMiddleware causes preview routes to fail.bootstrap/app.php as shown in Getting Started.Enable Debug Mode:
'debug' => env('THEME_DEBUG', true), // In config
Logs theme operations to storage/logs/filament-themes-manager.log.
Validate Theme Structure:
php artisan theme:validate
Checks for missing files, invalid JSON, and security issues.
Check Theme Events:
Listen for ThemeActivated or ThemeInstalled events to debug activation flows:
ThemeActivated::listen(function (Theme $theme) {
Log::info("Theme activated: {$theme->slug}");
});
Auto-Discovery:
base_path('themes') or resource_path('themes') are auto-discovered only if 'auto_discover' => true.Protected Themes:
'protected_themes' (e.g., ['default']) cannot be deleted via UI.default or admin.File Type Restrictions:
'allowed_file_types' to restrict uploaded files (e.g., block .php for security):'allowed_file_types' => ['css', 'scss', 'js', 'png', 'jpg'],
Custom Theme Sources:
ThemeInstaller to support additional sources (e.g., S3, FTP):class S3ThemeInstaller extends ThemeInstaller
{
public function installFromS3(string $bucket, string $key): Theme
{
// Custom logic
}
}
Register in config:
'installers' => [
's3' => S3ThemeInstaller::class,
],
Theme Events:
// In ThemeManagerService
event(new ThemeCustomized($theme, $user));
Listen globally or in a service provider.
Preview UI Customization:
php artisan vendor:publish --tag=filament-themes-manager-views
Modify resources/views/vendor/filament-themes-manager/preview-banner.blade.php.
Validation Rules:
ThemeValidator (see Implementation Patterns).Cache Themes:
'cache_duration' => 3600, // 1 hour (default)
Set to 0 to disable caching (useful for development).
Asset Compilation: Use Vite for themes to leverage Laravel Mix’s caching:
// vite.config.js in theme
export default defineConfig({
build: {
manifest: true,
outDir: 'public/build',
},
});
Bulk Operations:
Use Theme::whereNotIn('slug', ['default'])->delete() for safe bulk deletion (avoids protected themes).
How can I help you explore Laravel packages today?