- How does Capyrel detect Eloquent relationships automatically?
- Capyrel scans your database schema for foreign keys (e.g., *_id columns) and infers relationships like `belongsTo`, `hasMany`, or `belongsToMany` using Laravel’s conventions. It then generates the corresponding Eloquent methods and API resource relationships with `whenLoaded()` to prevent N+1 queries. For example, a `user_id` in the `posts` table triggers a `belongsTo(User::class)` relationship.
- Can I use Capyrel with an existing Laravel project that already has models?
- Yes, but you must use `model:scaffold` carefully. Capyrel will generate files for tables without existing models, but it won’t overwrite them. To avoid conflicts, manually merge custom logic (e.g., accessors, policies) after generation. Use the `--force` flag only if you’re certain about overwriting files.
- Does Capyrel support Laravel 10 or older versions?
- No, Capyrel requires Laravel 11 or 12 and PHP 8.2+. It leverages Laravel’s latest features like API resources, model events, and Livewire integration, which aren’t available in older versions. If you’re on Laravel 10, consider alternatives like Laravel Nova or manual scaffolding.
- How does Capyrel handle validation rules for generated form requests?
- Capyrel auto-generates validation rules based on column types (e.g., `string` → `required|string`, `email` → `required|email`). For nullable fields, it adds `nullable` to the rules. However, custom validation (e.g., regex patterns, conditional rules) must be added manually post-generation, as Capyrel follows strict Laravel conventions.
- Will Capyrel work with MongoDB or only SQL databases?
- Capyrel supports MongoDB, but schema inference is less reliable than SQL. For MongoDB, it relies on sampling or migration files to guess relationships. If your schema is complex or dynamic, you may need to manually adjust generated relationships or use `--skip-mongodb` to focus on SQL tables.
- Can I generate Livewire components alongside models and controllers?
- Yes! Capyrel includes Livewire scaffolding via `model:scaffold --with-livewire`. It generates basic CRUD components (e.g., `PostManager`, `PostForm`) with pre-wired relationships. However, you’ll need to customize the Blade templates and styling to match your project’s design system, as the default UI is minimal.
- How do I handle circular dependencies or orphaned foreign keys in my schema?
- Capyrel includes a `migrate:safe` command to detect schema issues like circular dependencies or orphaned FKs before generating code. Run it before scaffolding to catch problems early. For example, if `users` and `roles` have mutual FKs, Capyrel will warn you and suggest restructuring the schema.
- Are the generated Pest tests comprehensive enough for production?
- Generated tests cover basic CRUD operations (create, read, update, delete) and relationship assertions, but they’re not exhaustive. For production, you’ll need to extend them with edge cases like soft deletes, polymorphic relationships, or custom business logic. Use `model:tests --extend` to add supplementary test files.
- How does Capyrel handle real-time updates when the database schema changes?
- Use `model:watch` to auto-regenerate files when migrations run. This is useful in development but should be disabled in CI/CD to avoid flaky builds. For production, manually regenerate files after schema changes and review diffs to ensure no custom logic is lost.
- What alternatives exist if Capyrel’s conventions don’t fit my project?
- For more customization, consider Laravel Nova (paid, UI-focused) or manual scaffolding with tools like Laravel Jetstream or Filament. If you need lightweight generation, packages like `laravel-shift/blueprint` or `orchid/console` offer partial scaffolding. For MongoDB-heavy projects, Laravel’s native Eloquent for MongoDB may require custom model setup.