filament/schemas
Schema building tools for Filament: define, transform, and validate structured data for resources and forms with a simple, composable API. Lightweight package aimed at consistent schema definitions and reuse across your Filament app.
Installation
composer require filament/schemas
Publish the config (if needed):
php artisan vendor:publish --provider="Filament\Schemas\SchemasServiceProvider"
First Use Case: Basic Schema in a Livewire Component
use Filament\Schemas\Schemas;
use Livewire\Component;
class MyComponent extends Component
{
public function mount()
{
$this->schema = Schemas::make()
->schema([
Schemas::text('name', 'Name'),
Schemas::email('email', 'Email'),
]);
}
public function render()
{
return view('livewire.my-component', [
'schema' => $this->schema,
]);
}
}
Blade Integration
<x-filament::schemas::schema :schema="$schema" />
Key Files to Review
src/Schemas.php – Core schema builder.resources/views/components/schemas/schema.blade.php – Default UI rendering.Useful for forms with conditional fields or API-driven schemas:
$schema = Schemas::make();
if ($this->isAdmin) {
$schema->schema([
Schemas::password('admin_password', 'Admin Password'),
]);
}
Pair with filament/forms for validation and state management:
use Filament\Forms\Components\TextInput;
$form = Filament::makeForm()
->schema([
TextInput::make('name')->required(),
]);
$schema = Schemas::make()
->schema($form->getComponents());
Override default rendering per field type:
Schemas::text('name')
->label('Custom Label')
->helperText('This is a custom helper text')
->extraAttributes(['class' => 'bg-gray-100']);
Extract schemas into services or traits:
class UserSchemaService
{
public static function make()
{
return Schemas::make()
->schema([
Schemas::text('username'),
Schemas::date('birthday'),
]);
}
}
Listen for schema interactions (e.g., field changes):
Schemas::text('name')
->listen('change', function ($value) {
// Trigger side effects (e.g., API calls)
});
State Management
public $name = '';
Schemas::text('name')
->bindValue($this->name)
->listen('change', fn($value) => $this->name = $value);
Blade Component Paths
php artisan vendor:publish --tag="filament-schemas-views"
Validation Without Forms
filament/forms or manual validation:
$schema->validate(); // Throws exceptions if no form is attached.
dd($schema->toArray()); // Debug the schema definition.
Custom Field Types
Extend Filament\Schemas\Contracts\Field to add new field types:
class CustomField extends Field
{
protected static string $view = 'schemas.fields.custom';
}
Override Default Views Publish and modify the Blade views:
php artisan vendor:publish --tag="filament-schemas-views"
Conditional Rendering
Use visible() or hidden() methods:
Schemas::text('secret')
->visible(fn() => auth()->user()->isAdmin());
Localization Translate labels/helpers via Laravel’s translation system:
Schemas::text('name')
->label(__('filament::schemas.fields.name'));
How can I help you explore Laravel packages today?