Inserting a Blade view into a schema
You may use a “view” component to insert a Blade view into a schema arbitrarily:resources/views/filament/schemas/components/chart.blade.php file.
You may pass data to this view through the viewData() method:
Rendering the component’s child schema
You may pass an array of child schema components to theschema() method of the component:
schema() using the $getChildSchema() function:
Accessing the state of another component in the Blade view
Inside the Blade view, you may access the state of another component in the schema using the$get() function:
Accessing the Eloquent record in the Blade view
Inside the Blade view, you may access the current Eloquent record using the$record variable:
Accessing the current operation in the Blade view
Inside the Blade view, you may access the current operation, usuallycreate, edit or view, using the $operation variable:
Accessing the current Livewire component instance in the Blade view
Inside the Blade view, you may access the current Livewire component instance using$this:
Accessing the current component instance in the Blade view
Inside the Blade view, you may access the current component instance using$schemaComponent. You can call public methods on this object to access other information that may not be available in variables:
Inserting a Livewire component into a schema
You may insert a Livewire component directly into a schema:When inserting a Livewire component into the schema, there are limited capabilities. Only serializable data is accessible from the nested Livewire component, since they are rendered separately. As such, you can’t render a child schema, access another component’s live state, access the current Livewire component instance, or access the current component instance. Only static data that you pass to the Livewire component, and the current record are accessible. Situations where you should render a nested Livewire component instead of a Blade view are rare because of these limitations.
key() to each:
Passing parameters to a Livewire component
You can pass an array of parameters to a Livewire component:As well as allowing a static value, the make() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.
make() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.Learn more about utility injection.
Component
$component
Filament\Schemas\Components\Component
The current component instance.
Get function
$get
Filament\Schemas\Components\Utilities\Get
A function for retrieving values from the current schema data. Validation is not run on form fields.
Livewire
$livewire
Livewire\Component
The Livewire component instance.
Eloquent model FQN
$model
?string<Illuminate\Database\Eloquent\Model>
The Eloquent model FQN for the current schema.
Operation
$operation
string
The current operation being performed by the schema. Usually
create, edit, or view.Eloquent record
$record
?Illuminate\Database\Eloquent\Model
The Eloquent record for the current schema.
mount() method:
Accessing the current record in the Livewire component
You can access the current record in the Livewire component using the$record parameter in the mount() method, or the $record property:
null. If you’d like to hide the Livewire component when the record is null, you can use the hidden() method:
Lazy loading a Livewire component
You may allow the component to lazily load using thelazy() method:
Custom component classes
You may create your own custom component classes and views, which you can reuse across your project, and even release as a plugin to the community. To create a custom component class and view, you may use the following command:resources/views/filament/schemas/components/chart.blade.php.
You may use the same utilities as you would when inserting a Blade view into a schema to render the component’s child schema, access another component’s live state, access the current Eloquent record, access the current operation, access the current Livewire component instance, and access the current component instance.
Filament schema components are not Livewire components. Defining public properties and methods on a schema component class will not make them accessible in the Blade view.
Adding a configuration method to a custom component class
You may add a public method to the custom component class that accepts a configuration value, stores it in a protected property, and returns it again from another public method:$getHeading() function:
Allowing utility injection in a custom component configuration method
Utility injection is a powerful feature of Filament that allows users to configure a component using functions that can access various utilities. You can allow utility injection by ensuring that the parameter type and property type of the configuration allows the user to pass aClosure. In the getter method, you should pass the configuration value to the $this->evaluate() method, which will inject utilities into the user’s function if they pass one, or return the value if it is static:
heading() method, and inject any utility as a parameter:
Accepting a configuration value in the constructor of a custom component class
You may accept a configuration value in themake() constructor method of the custom component and pass it to the corresponding setter method:
Calling component methods from JavaScript
Sometimes you need to call a method on the component class from JavaScript in the Blade view. For example, you might want to fetch data asynchronously or perform some server-side computation. Filament provides a way to expose methods on your component class to JavaScript using the#[ExposedLivewireMethod] attribute.
Exposing a method
To expose a method to JavaScript, add the#[ExposedLivewireMethod] attribute to a public method on your custom component class:
Only methods marked with
#[ExposedLivewireMethod] can be called from JavaScript. This is a security measure to prevent arbitrary method execution.Calling the method from JavaScript
In your Blade view, you may call the exposed method using$wire.callSchemaComponentMethod(). The first argument is the component’s key (available via $getKey()), and the second argument is the method name. You may pass arguments as a third argument:
Preventing re-renders
By default, calling an exposed method will trigger a re-render of the Livewire component. If your method doesn’t need to update the UI, you may add Livewire’s#[Renderless] attribute alongside #[ExposedLivewireMethod] to skip the re-render: