PHP code example of cuongpham2107 / filament-theme-customizer

1. Go to this page and download the library: Download cuongpham2107/filament-theme-customizer 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/ */

    

cuongpham2107 / filament-theme-customizer example snippets


use CuongPham\FilamentThemeCustomizer\ThemeCustomizerPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->plugin(
            ThemeCustomizerPlugin::make()
                // Optional: button position ('bottom-right' or 'bottom-left', default: 'bottom-right')
                ->position('bottom-right')
                
                // 1. Permission to customize and save personal preferences to DB
                ->canCustomize(fn (): bool => auth()->check())
                
                // 2. Permission for Super Admin to set the System-Wide Global Default
                ->canSetGlobalDefault(fn (): bool => auth()->user()?->hasRole('super_admin') ?? false)
        );
}

// Grant access only to Super Admins
ThemeCustomizerPlugin::make()
    ->canCustomize(fn (): bool => auth()->user()?->can('manage_theme') ?? false)

// Only enable in local development
ThemeCustomizerPlugin::make()
    ->canCustomize(app()->isLocal())

// Dependency injection in closure
ThemeCustomizerPlugin::make()
    ->canCustomize(function (?\App\Models\User $user): bool {
        return $user && $user->is_admin;
    })
bash
php artisan vendor:publish --tag=filament-theme-customizer-views