Skip to main content
The FluxManager class is the core manager for the Flux UI component library. It handles component registration, asset rendering, and provides utility methods for working with Flux components.

Overview

The FluxManager is typically accessed through the Flux facade, but can also be accessed directly via the container:
use Flux\FluxManager;

$flux = app('flux'); // or app(FluxManager::class)

Properties

hasRenderedAssets

public bool $hasRenderedAssets = false
Tracks whether Flux assets (scripts/styles) have been rendered on the current page.

Methods

boot()

Bootstrap the FluxManager instance.
public function boot(): void
This method is called automatically by the service provider. It sets up Livewire event listeners and boots components.

pro()

Check if Flux Pro is installed.
public function pro(): bool
Returns: true if the livewire/flux-pro package is installed, false otherwise Example:
if ($flux->pro()) {
    // Access Flux Pro features
}

ensurePro()

Ensure Flux Pro is installed, throw an exception if not.
public function ensurePro(): void
Throws: \Exception if Flux Pro is not installed Example:
$flux->ensurePro(); // Throws if Pro is not installed

scripts()

Generate the Flux JavaScript script tag.
public function scripts($options = []): string
options
array
default:"[]"
Configuration optionsOptions:
  • nonce (string): CSP nonce value for the script tag
Returns: HTML script tag string Example:
echo $flux->scripts();
echo $flux->scripts(['nonce' => 'xyz123']);
This method automatically marks assets as rendered and delegates to AssetManager::scripts().

fluxAppearance()

Generate the Flux appearance management script and styles.
public function fluxAppearance($options = []): string
options
array
default:"[]"
Configuration optionsOptions:
  • nonce (string): CSP nonce value for inline scripts and styles
Returns: HTML string containing inline styles and scripts for dark mode support Example:
echo $flux->fluxAppearance();

editorStyles()

Generate the Flux editor CSS link tag (Flux Pro only).
public function editorStyles(): string
Returns: HTML link tag for editor CSS Example:
echo $flux->editorStyles();

editorScripts()

Generate the Flux editor JavaScript script tag (Flux Pro only).
public function editorScripts(): string
Returns: HTML script tag for editor JavaScript Example:
echo $flux->editorScripts();

classes()

Create a class builder instance for constructing CSS class strings.
public function classes($styles = null): ClassBuilder
styles
string|null
default:"null"
Optional CSS classes to initialize the builder with
Returns: ClassBuilder instance Example:
$builder = $flux->classes();
$builder = $flux->classes('bg-white text-gray-900');

disallowWireModel()

Throw an exception if wire: attributes are present.
public function disallowWireModel($attributes, $componentName): void
attributes
ComponentAttributeBag
required
The attribute bag to check
componentName
string
required
The component name for the error message
Throws: \Exception if any wire:* attributes are found Example:
$flux->disallowWireModel($attributes, 'flux:button');

splitAttributes()

Split an attribute bag into two bags based on attribute names.
public function splitAttributes(
    $attributes, 
    $by = ['class', 'style'], 
    $strict = false
): array
attributes
ComponentAttributeBag
required
The attribute bag to split
by
array
default:"['class', 'style']"
Array of attribute names to split by
strict
bool
default:"false"
If true, uses exact matching. If false, uses startsWith matching
Returns: Array with two ComponentAttributeBag instances: [matched, unmatched] Example:
// Split class and style attributes
[$styling, $remaining] = $flux->splitAttributes($attributes);

// Split data- attributes (non-strict)
[$dataAttrs, $others] = $flux->splitAttributes($attributes, ['data-']);

// Split specific attributes (strict)
[$id, $others] = $flux->splitAttributes($attributes, ['id', 'name'], true);

forwardedAttributes()

Extract specific attributes from an attribute bag for forwarding to nested components.
public function forwardedAttributes($attributes, $propKeys): array
attributes
ComponentAttributeBag
required
The attribute bag to extract from
propKeys
array
required
Array of prop keys to extract (supports both camelCase and kebab-case)
Returns: Array of extracted prop values with keys converted to camelCase Example:
// Extract specific props for forwarding
$props = $flux->forwardedAttributes($attributes, ['wireModel', 'placeholder']);

// Supports kebab-case conversion
// If attribute has 'wire-model', it will be extracted as 'wireModel'

attributesAfter()

Extract attributes with a specific prefix and remove them from the original bag.
public function attributesAfter(
    $prefix, 
    $attributes, 
    $default = []
): ComponentAttributeBag
prefix
string
required
The prefix to match (e.g., ‘icon:’)
attributes
ComponentAttributeBag
required
The attribute bag to extract from (modified in place)
default
array
default:"[]"
Default attributes for the new bag
Returns: New ComponentAttributeBag with prefix-matched attributes (prefix removed from keys) Example:
// Extract icon: prefixed attributes
$iconAttrs = $flux->attributesAfter('icon:', $attributes);
// icon:class="text-blue-500" becomes class="text-blue-500" in $iconAttrs

applyInset()

Generate CSS classes for inset positioning.
public function applyInset(
    $inset, 
    $top, 
    $right, 
    $bottom, 
    $left
): string
inset
bool|string|null
required
Inset specification: true for all sides, space-separated sides, or null
top
string
required
CSS class for top inset
right
string
required
CSS class for right inset
bottom
string
required
CSS class for bottom inset
left
string
required
CSS class for left inset
Returns: Space-separated CSS class string Example:
// Apply all sides
$classes = $flux->applyInset(true, 'pt-4', 'pr-4', 'pb-4', 'pl-4');
// Returns: 'pt-4 pr-4 pb-4 pl-4'

// Apply specific sides
$classes = $flux->applyInset('top bottom', 'pt-4', 'pr-4', 'pb-4', 'pl-4');
// Returns: 'pt-4 pb-4'

// No inset
$classes = $flux->applyInset(null, 'pt-4', 'pr-4', 'pb-4', 'pl-4');
// Returns: ''

componentExists()

Check if a Flux component exists.
public function componentExists($name): bool
name
string
required
The component name to check
Returns: true if the component exists, false otherwise Example:
if ($flux->componentExists('button')) {
    // Component exists
}
This method accounts for Laravel version differences in view hashing (xxh128 in Laravel 12+, md5 in earlier versions).

markAssetsRendered()

Mark assets as rendered.
public function markAssetsRendered(): void
Sets $hasRenderedAssets to true. Called automatically by scripts() and fluxAppearance().