- Can I use egeloen/ordered-form directly in Laravel without Symfony?
- No, this package requires Symfony’s Form component. You’ll need to bridge Laravel’s form system (e.g., `Form::macro` or `FormRequest`) with Symfony’s `FormFactory` via a custom adapter or a package like `laravel-symfony`. Start with a proof-of-concept service provider to test compatibility.
- What Laravel versions support this package?
- The package itself targets Symfony 5.x+, so Laravel 8.x+ is recommended (PHP 8.0+). Older Laravel versions may need additional polyfills or Symfony version adjustments. Test thoroughly with your specific Laravel release, as form handling differs across versions.
- How do I define field ordering in Laravel using this package?
- Use the `position` option (e.g., `['position' => 'first']`) or associative arrays for `before`/`after` rules, just like Symfony. Example: `$builder->add('name', TextType::class, ['position' => ['before' => 'email']])`. Wrap the Symfony `FormBuilder` in a Laravel service to apply these rules.
- Will this work with Laravel Livewire or Inertia.js forms?
- Yes, but ordering logic must be applied server-side. Livewire/Inertia forms still rely on Laravel’s form rendering pipeline. Use the package’s Symfony integration in your backend, then pass the ordered fields to the frontend. Client-side JS can’t override server-side ordering rules.
- Are there conflicts if Laravel already uses Symfony components?
- Potential conflicts may arise if Laravel or other packages use a different Symfony version. Lock dependencies in `composer.json` (e.g., `symfony/form:^5.4`) and test for version compatibility. Use `composer why symfony/form` to audit dependencies.
- How do I persist form field positions for users (e.g., save preferences)?
- Store positions in Laravel’s `session`, `database`, or `cache`. Example: Use a `FormPosition` model with `user_id` and `form_type` fields. Sync positions via middleware or a service that injects the `position` option dynamically into the Symfony `FormBuilder`.
- Does this package support nested forms or dynamic fields?
- The package handles nested fields if they’re part of the Symfony `FormType` hierarchy, but dynamic fields (added via JavaScript) require manual reordering. Test with your specific use case—complex nested forms may need custom `FormOrderer` logic to resolve dependencies.
- What’s a simpler alternative for basic field reordering in Laravel?
- For simple cases, use Laravel’s `Form::macro` to sort fields manually: `Form::macro('orderFields', fn($fields) => collect($fields)->sortBy(...))`. Packages like `spatie/laravel-form-builder` also offer field management without Symfony dependencies.
- How do I test form ordering logic in Laravel?
- Mock the Symfony `FormFactory` and `OrderedExtension` in PHPUnit tests. Verify field order by inspecting the rendered HTML or the `FormInterface` structure. Example: `$form->createView()->children` should reflect your `position` rules. Adapt the package’s existing tests as a starting point.
- What if integration fails—are there fallbacks?
- If Symfony integration proves too complex, fall back to client-side JS (e.g., SortableJS) or server-side array manipulation. For critical forms, implement a hybrid approach: use the package for static ordering and JS for dynamic adjustments, with server-side validation to enforce rules.