Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Schemas Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require filament/schemas
    

    Publish the config (if needed):

    php artisan vendor:publish --provider="Filament\Schemas\SchemasServiceProvider"
    
  2. 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,
            ]);
        }
    }
    
  3. Blade Integration

    <x-filament::schemas::schema :schema="$schema" />
    
  4. Key Files to Review


Implementation Patterns

1. Dynamic Schema Generation

Useful for forms with conditional fields or API-driven schemas:

$schema = Schemas::make();
if ($this->isAdmin) {
    $schema->schema([
        Schemas::password('admin_password', 'Admin Password'),
    ]);
}

2. Integration with Livewire Forms

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());

3. Customizing UI Components

Override default rendering per field type:

Schemas::text('name')
    ->label('Custom Label')
    ->helperText('This is a custom helper text')
    ->extraAttributes(['class' => 'bg-gray-100']);

4. Schema Reusability

Extract schemas into services or traits:

class UserSchemaService
{
    public static function make()
    {
        return Schemas::make()
            ->schema([
                Schemas::text('username'),
                Schemas::date('birthday'),
            ]);
    }
}

5. Event Handling

Listen for schema interactions (e.g., field changes):

Schemas::text('name')
    ->listen('change', function ($value) {
        // Trigger side effects (e.g., API calls)
    });

Gotchas and Tips

Pitfalls

  1. State Management

    • Schemas are stateless by default. Use Livewire properties or a form component to persist data:
      public $name = '';
      
      Schemas::text('name')
          ->bindValue($this->name)
          ->listen('change', fn($value) => $this->name = $value);
      
  2. Blade Component Paths

    • Ensure the view namespace matches your Laravel setup. If using custom paths, publish the views:
      php artisan vendor:publish --tag="filament-schemas-views"
      
  3. Validation Without Forms

    • Schemas alone do not validate. Pair with filament/forms or manual validation:
      $schema->validate(); // Throws exceptions if no form is attached.
      

Debugging Tips

  • Inspect Rendered HTML: Use browser dev tools to verify field attributes.
  • Log Schema Structure:
    dd($schema->toArray()); // Debug the schema definition.
    
  • Check for Conflicts: If styles break, ensure no CSS conflicts with Filament’s Tailwind classes.

Extension Points

  1. Custom Field Types Extend Filament\Schemas\Contracts\Field to add new field types:

    class CustomField extends Field
    {
        protected static string $view = 'schemas.fields.custom';
    }
    
  2. Override Default Views Publish and modify the Blade views:

    php artisan vendor:publish --tag="filament-schemas-views"
    
  3. Conditional Rendering Use visible() or hidden() methods:

    Schemas::text('secret')
        ->visible(fn() => auth()->user()->isAdmin());
    
  4. Localization Translate labels/helpers via Laravel’s translation system:

    Schemas::text('name')
        ->label(__('filament::schemas.fields.name'));
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport