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

Parsley Bundle Laravel Package

c0ntax/parsley-bundle

Symfony bundle that maps Symfony Form constraints and entity annotations to Parsley.js data-parsley-* attributes for client-side validation. Includes basic configuration (enable/trigger) and supports Email, Length, Pattern, Min/Max, Required, and Range.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Symfony Native Fit: The package is tightly coupled with Symfony’s Form Component and Validator, making it a zero-effort integration for Symfony applications. For Laravel, the fit is partial—Laravel’s validation system (e.g., Illuminate\Validation\Validator) is incompatible with Symfony’s Constraint system, requiring custom adapters or middleware to bridge the gap.
  • Validation Paradigm Alignment: Leverages Symfony’s declarative validation (annotations, YAML, PHP constraints) to auto-generate Parsley.js attributes (data-parsley-*). This aligns with Laravel’s validation rules (e.g., Rule::minLength()), but Laravel lacks Symfony’s constraint-based system, necessitating manual mapping or a custom wrapper.
  • Extensibility: Supports custom directives via DirectiveInterface, allowing TPMs to extend functionality (e.g., adding Laravel-specific validators like unique or confirmed). However, this requires developer effort to implement and maintain.
  • Form Component Dependency: Relies on Symfony’s FormBuilder, which is not natively available in Laravel. Workarounds include:
    • Using Symfony’s Form Component in Laravel (via symfony/form package).
    • Building a lightweight Laravel wrapper to mimic Symfony’s form structure.
    • Integrating with Laravel Collective’s HTML package (if using older Laravel versions).

Integration Feasibility

  • Symfony: High feasibility—drop-in installation with minimal configuration. Auto-magically converts Symfony constraints to Parsley.js attributes.
  • Laravel: Medium feasibility—requires custom integration:
    • Option 1: Use Symfony’s Form Component in Laravel (adds ~5MB to dependencies).
    • Option 2: Build a Laravel-specific adapter to map Laravel validation rules to Parsley.js (e.g., Illuminate\Validation\Ruledata-parsley-*).
    • Option 3: Use Laravel Mix/Webpack to manually inject Parsley.js and attributes (highest flexibility, highest maintenance).
  • Frontend Stack: Assumes jQuery (Parsley.js dependency) and Symfony’s Twig templating. For modern Laravel stacks (e.g., Vue/React + Inertia), requires:
    • SSR/CSR Compatibility: Parsley.js must be loaded client-side (not SSR-friendly by default).
    • Attribute Injection: Custom logic to inject data-parsley-* attributes into Blade/Vue/React components.

Technical Risk

Risk Area Symfony Risk Laravel Risk Mitigation Strategy
Validation Mismatch Low Medium Test edge cases (e.g., Range, Pattern).
Parsley.js Dependency Low Medium Bundle Parsley.js via npm/yarn or CDN.
Form Component Gap None High Use Symfony Form Component or build adapter.
Twig vs. Blade None Medium Abstract attribute injection logic.
Performance Overhead Low Low Minify Parsley.js; lazy-load if needed.
Maintenance Burden Low High (Laravel) Contribute to package or fork for Laravel.
Deprecated Features Low N/A Monitor Parsley.js/Symfony updates.

Key Questions for TPM

  1. Stack Alignment:
    • Are we using Symfony or Laravel? If Laravel, what’s the validation/form strategy (e.g., pure Illuminate\Validation or Symfony integration)?
    • Is Parsley.js already in use, or is this a new dependency?
  2. Validation Scope:
    • Do we need client-side-only validations, or server-client sync?
    • Are there unsupported Symfony constraints (e.g., Callback, Expression) that require custom directives?
  3. Frontend Architecture:
    • Is the app Twig-based (Symfony) or Blade/Vue/React (Laravel)? How are form attributes rendered?
    • Is jQuery available, or must Parsley.js be used in a non-jQuery environment?
  4. Long-Term Viability:
    • Is the package actively maintained? (Last release: 2018—risky for new projects.)
    • Are there alternatives (e.g., Vega, Htmx for progressive enhancement)?
  5. Testing and QA:
    • How will we test validation parity between client/server?
    • Are there edge cases (e.g., dynamic forms, conditional validation) not covered by the bundle?

Integration Approach

Stack Fit

Component Symfony Fit Laravel Fit Workaround
Form Handling Native Partial (Symfony Form) Use symfony/form or build adapter.
Validation Native Partial (Illuminate\Validation) Map Laravel rules to Parsley.js.
Templating Twig Blade/Vue/React Abstract attribute injection.
Parsley.js CDN/npm CDN/npm Bundle via Laravel Mix.
Dependency Mgmt Composer Composer/npm Use symfony/form or custom package.

Migration Path

Symfony Integration (Low Risk)

  1. Installation:
    composer require c0ntax/parsley-bundle
    
  2. Configuration:
    # config/packages/c0ntax_parsley.yaml
    c0ntax_parsley:
        enabled: true
        field:
            trigger: blur
    
  3. Enable Bundle:
    // config/bundles.php
    C0ntax\ParsleyBundle\C0ntaxParsleyBundle::class => ['all' => true],
    
  4. Usage:
    • Auto-magic: Symfony constraints in forms/entities → Parsley.js attributes.
    • Custom Rules: Use parsleys option in FormBuilder.
  5. Frontend:
    • Include Parsley.js (CDN or npm):
      <script src="https://cdn.jsdelivr.net/npm/parsleyjs@latest/dist/parsley.min.js"></script>
      
    • Initialize:
      $(document).ready(function() { $('form').parsley(); });
      

Laravel Integration (Medium Risk)

  1. Option A: Symfony Form Component (Highest Compatibility)

    • Install Symfony Form:
      composer require symfony/form symfony/validator
      
    • Follow Symfony integration steps above.
    • Downside: Adds ~5MB to dependencies.
  2. Option B: Custom Laravel Adapter (Lightweight)

    • Step 1: Create a service to map Laravel validation rules to Parsley.js:
      // app/Services/ParsleyValidator.php
      class ParsleyValidator {
          public static function getParsleyAttributes(array $rules): array {
              $mapping = [
                  'required' => 'data-parsley-required="true"',
                  'min' => fn($len) => sprintf('data-parsley-minlength="%d"', $len),
                  // Add other mappings...
              ];
              $attributes = [];
              foreach ($rules as $rule => $value) {
                  if (isset($mapping[$rule])) {
                      $attributes[] = is_callable($mapping[$rule])
                          ? call_user_func($mapping[$rule], $value)
                          : $mapping[$rule];
                  }
              }
              return $attributes;
          }
      }
      
    • Step 2: Extend Laravel’s FormRequest or use a form builder (e.g., Laravel Collective HTML) to inject attributes:
      // In a FormRequest or controller
      $parsleyAttrs = ParsleyValidator::getParsleyAttributes($request->rules());
      return view('form', ['parsley_attrs' => $parsleyAttrs]);
      
      <input type="text" {{ $parsley_attrs }}>
      
    • Step 3: Load Parsley.js via Laravel Mix:
      // resources/js/app.js
      import 'parsleyjs/dist/parsley.min.js';
      document.addEventListener('DOMContentLoaded', () => {
          $('form').parsley();
      });
      
  3. Option C: Manual Attribute Injection (High Flexibility)

    • Use Blade directives or JavaScript to inject Parsley attributes dynamically:
      @parsley(['required', 'min:3'])
      <input type="text
      
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.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views