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

Liform Laravel Package

dariotilgner/liform

Serialize Symfony Forms into JSON Schema for documentation, validation, and client-side form generation. Works with generators like liform-react or json-editor, and powers LiformBundle. Use as a standalone library to keep backend and frontend forms in sync.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Symfony Form → JSON Schema Conversion: The package bridges Symfony Forms (a declarative form system) with JSON Schema (a structured data validation format), enabling API-first design for form-based workflows. This is valuable for:
    • Backend-for-Frontend (BFF) patterns: Generating dynamic frontend forms from backend definitions.
    • API contracts: Validating client-submitted data against schema constraints (e.g., in REST/gRPC APIs).
    • Admin panels/CRUD systems: Auto-generating form UIs from database models (e.g., Laravel Nova-like interfaces).
  • Laravel Compatibility: While the package targets Symfony, Laravel’s Symfony Components (e.g., symfony/form, symfony/validator) make integration feasible with minimal overhead. Laravel’s Form Requests or API Resources could leverage this for schema generation.
  • Limitation: No native Laravel-specific features (e.g., Eloquent model binding, Laravel Validation rules). Requires manual mapping or wrapper logic.

Integration Feasibility

  • Core Dependencies:
    • Requires symfony/form (≥5.0) and symfony/validator (≥5.0). Laravel already bundles these via illuminate/support (indirectly).
    • JSON Schema Output: Compatible with tools like JSON Schema Validator or frontend libraries (e.g., React Hook Form, Vue VeeValidate).
  • Laravel-Specific Challenges:
    • Form Builder Differences: Laravel’s Form::macro() or collective/html diverge from Symfony’s FormBuilder. May need a wrapper to normalize form definitions.
    • Validation Rules: Laravel’s Validator uses a different rule syntax (e.g., required|email). Requires translation logic (e.g., required"type": "string", "pattern": "^[^@]+@[^@]+\.[^@]+$" for email).
    • Dynamic Forms: Laravel’s FormRequest or Livewire forms may need adaptation to Symfony’s FormType structure.

Technical Risk

Risk Area Severity Mitigation
Schema Accuracy High Validate generated schemas against test cases (e.g., edge cases like nested forms).
Performance Overhead Medium Benchmark schema generation for complex forms (e.g., 50+ fields).
Maintenance Burden Medium Monitor Symfony Form updates for breaking changes (e.g., PHP 8.2+ features).
Laravel-Symfony Gaps High Build a facade/wrapper to abstract Symfony-specific logic (e.g., FormType → Laravel FormRequest).
Frontend Integration Low Ensure schema output aligns with frontend tooling (e.g., OpenAPI/Swagger compatibility).

Key Questions

  1. Use Case Clarity:
    • Is this for API validation (e.g., OpenAPI specs) or frontend form generation (e.g., React/Vue)?
    • Will forms be static (e.g., CRUD) or dynamic (e.g., user-defined workflows)?
  2. Laravel-Specific Needs:
    • Can existing FormRequest classes be adapted to Symfony FormType, or is a custom wrapper needed?
    • How will Laravel’s Validator rules map to JSON Schema constraints?
  3. Performance:
    • What’s the expected form complexity (e.g., 10 fields vs. 100+ nested fields)?
    • Will schema generation happen at runtime (e.g., per-request) or compile-time (e.g., cached)?
  4. Tooling:
    • Will the schema be used for client-side validation (e.g., frontend libraries) or server-side (e.g., API gateways)?
    • Are there existing tools (e.g., Swagger UI, Redoc) to visualize the schema?
  5. Long-Term Viability:

Integration Approach

Stack Fit

  • Laravel Compatibility:
    • Symfony Components: Laravel already uses symfony/form and symfony/validator under the hood (via illuminate/support). No additional composer dependencies are strictly required if using Laravel’s built-in components.
    • Form Systems:
      • Symfony Forms: Directly compatible if using Laravel’s Form facade (though limited).
      • Laravel Form Requests: Requires translation logic (e.g., FormRequestFormType).
      • Livewire/Inertia: Schema generation could feed into frontend validation (e.g., via useForm in Inertia).
  • Frontend Integration:

Migration Path

  1. Assessment Phase:
    • Audit existing forms (e.g., FormRequest classes, Livewire components) to identify compatibility gaps.
    • Test schema generation with a subset of forms (e.g., 3–5 critical forms).
  2. Wrapper Layer:
    • Create a Laravel facade to abstract Symfony FormType logic:
      // Example: liform-facade/src/Liform.php
      class Liform {
          public static function fromFormRequest(FormRequest $request): string {
              $formType = self::convertRequestToFormType($request);
              return (new \Dariotilgner\Liform\Liform())->render($formType);
          }
      }
      
    • Map Laravel Validator rules to JSON Schema constraints (e.g., required|email"type": "string", "format": "email").
  3. Incremental Rollout:
    • Phase 1: Generate schemas for read-only APIs (e.g., documentation).
    • Phase 2: Integrate with frontend validation (e.g., React Hook Form).
    • Phase 3: Extend to dynamic form generation (e.g., admin panels).
  4. Fallback Mechanism:
    • Cache generated schemas (e.g., Redis) to avoid runtime overhead.
    • Provide a fallback schema for unsupported form types.

Compatibility

Laravel Feature Compatibility Workaround
Form Requests Low (different structure) Write a converter to transform FormRequest to FormType.
Eloquent Model Binding Medium Use FormType extensions to bind to Eloquent models.
Livewire Components High (schema as prop) Pass schema as a Livewire prop to frontend.
API Resources Medium Generate schema from FormRequest used in APIResource.
Validation Rules Low (syntax mismatch) Build a rule-to-schema mapper (e.g., `required
Localization Medium Extend Liform to support Symfony’s translation system.

Sequencing

  1. Proof of Concept (1–2 weeks):
    • Convert 1–2 FormRequest classes to FormType and generate schemas.
    • Validate output with a frontend library (e.g., React Hook Form).
  2. Wrapper Development (2–3 weeks):
    • Build the Laravel facade and rule mapper.
    • Test with edge cases (nested forms, conditional fields).
  3. Integration (3–4 weeks):
    • Integrate with API documentation (Swagger/OpenAPI).
    • Connect to frontend validation (e.g., Inertia/Livewire).
  4. Optimization (Ongoing):
    • Cache schemas to reduce runtime cost.
    • Monitor performance for large forms (>50 fields).

Operational Impact

Maintenance

  • Dependencies:
    • Symfony Form: Laravel’s illuminate/support bundles symfony/form (v5.x). Upgrade risks:
      • PHP 8.2+ features may break compatibility.
      • Mitigation: Pin Symfony version in composer.json or use a wrapper to isolate changes.
    • Liform Package:
      • Last release: 2021—risk of stagnation.
      • **
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.
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge