- Can I use this bundle directly in Laravel, or is it only for Symfony?
- This bundle is designed for Symfony, but you can use its core dependency, **dragonmantank/cron-expression**, in Laravel. For form handling, integrate Symfony’s Form Component or use Laravel packages like **laravelcollective/html** with custom validation logic. The Doctrine DBAL type won’t work natively in Laravel, but you can store cron expressions as strings and validate them manually.
- What Laravel versions does this bundle support?
- The bundle itself only supports Symfony 5.4+, but its underlying library (**dragonmantank/cron-expression**) works with PHP 8.1+. For Laravel, ensure your project uses PHP 8.1+ and manually integrate the cron-expression package. Laravel 9/10+ will work best due to PHP version alignment.
- How do I validate cron expressions in Laravel forms without Doctrine?
- Use **dragonmantank/cron-expression** directly with Laravel’s validator. Add a custom rule via `Validator::extend()` to check cron syntax, then apply it to form fields. Example: `Validator::extend('cron', function ($attribute, $value, $parameters) { return CronExpression::isValidExpression($value); });` Then use `Rule::cron()` in your validation rules.
- Does this bundle work with Eloquent models instead of Doctrine?
- No, the bundle’s **CronExpressionType** is Doctrine DBAL-specific. For Eloquent, store cron expressions as strings (e.g., `string $schedule`) and validate them on-the-fly using **dragonmantank/cron-expression**. You can create a custom accessor to parse the expression when needed, like `$model->getParsedSchedule()`.
- What if my cron expressions have custom validation rules (e.g., time zones or domain-specific constraints)?
- The bundle uses **dragonmantank/cron-expression** under the hood, which supports standard cron syntax. For custom rules, extend Symfony’s validator or Laravel’s validator with a custom rule. Example: `CronExpression::factory($value)->timezone('America/New_York')->isValid()` for timezone-aware validation.
- Will this bundle slow down my application if used in high-traffic forms?
- The bundle’s validation is lightweight, but parsing cron expressions in bulk (e.g., thousands of form submissions) could introduce latency. Test performance in staging and consider caching parsed expressions if needed. The **dragonmantank/cron-expression** library is optimized, but always benchmark in your specific use case.
- How do I migrate from manual cron validation to this bundle in Symfony?
- Start by replacing manual validation with the **CronExpressionType** in forms. Update your entity mappings to use `CronExpressionType::CRON_EXPRESSION_TYPE` for database storage. Run migrations to adjust schema, then gradually replace legacy cron parsing logic with the bundle’s utilities. Example: `$builder->add('schedule', CronExpressionType::class, ['validation_message' => 'Invalid cron: {{ value }}']);`
- Are there alternatives to this bundle for Laravel?
- For Laravel, consider **spatie/laravel-cron-expression** (a Laravel-specific wrapper for **dragonmantank/cron-expression**) or **laravel-scheduler** for task scheduling. If you need form integration, combine **dragonmantank/cron-expression** with **laravelcollective/html** or **craftzdog/laravel-form-request-validation** for custom form types.
- How do I handle edge cases like invalid cron expressions in production?
- The bundle provides default validation messages, but customize them via the `validation_message` option in forms. For production, log invalid inputs (e.g., using Laravel’s `report()` or Symfony’s error logger) and consider adding a fallback cron expression (e.g., `* * * * *`) if validation fails critically.
- Does this bundle support cron expressions with seconds (e.g., `* * * * * *`)?
- Yes, the underlying **dragonmantank/cron-expression** library supports full cron syntax, including seconds. The bundle’s form field and Doctrine type will handle these expressions natively. No additional configuration is required for second-level precision.