- What problem does cline/morphism solve in Laravel applications?
- It standardizes polymorphic key resolution (e.g., `id`, `uuid`, or custom columns) across models, eliminating repetitive logic in `morphTo`, API responses, or query filters. Ideal for multi-model systems where key formats vary.
- How do I install and set up cline/morphism in Laravel?
- Run `composer require cline/morphism`, then bind a resolver in `AppServiceProvider`. The package integrates with Laravel’s service container, requiring minimal configuration. Follow the [Basic Usage](https://github.com/faustbrian/morphism#doc-cookbooks-basic-usage) guide for registry setup.
- Does cline/morphism work with Laravel 11 or older versions?
- No, it explicitly requires **PHP 8.4+** and **Laravel 12+**. If you’re on Laravel 11 or below, check alternatives like custom accessors or Laravel’s native `morphMap` for key resolution.
- Can I use this package for API resource serialization?
- Yes. The package’s registry can dynamically resolve polymorphic keys in `toArray()` or `toResponse()`, ensuring consistent key formats (e.g., UUIDs) across API payloads without manual checks.
- How does cline/morphism handle custom key formats like UUIDs or composite keys?
- It supports custom resolvers via the registry. Define a resolver class to map non-standard keys (e.g., UUIDs) to your model’s primary column, then bind it in the service container.
- Is there a performance benefit over manual polymorphic key resolution?
- Yes, it centralizes logic, reducing duplicate code in models, API resources, or query scopes. Benchmark your use case, but the package avoids runtime overhead by leveraging Laravel’s container.
- Can I enforce strict key mapping for all models in my app?
- Yes, the package offers [strict enforcement](https://github.com/faustbrian/morphism#doc-cookbooks-strict-enforcement) to require all models register their key columns, preventing runtime errors from unmapped relationships.
- Are there any known limitations or edge cases?
- The package is new (no public dependents) and lacks documentation for nested polymorphic relationships or Octane compatibility. Test thoroughly, especially if using custom resolvers or complex query filters.
- How does cline/morphism compare to Laravel’s native `morphMap` or custom accessors?
- Unlike `morphMap` (limited to string keys), this package handles dynamic columns (e.g., `uuid`) and integrates with the service container. Custom accessors work but require per-model boilerplate; this centralizes logic.
- What’s the migration path if I already handle polymorphic keys manually?
- Audit your models for repetitive key resolution (e.g., `switch` statements or traits), then incrementally replace them. Start with API resources or query filters, binding the resolver in `AppServiceProvider` as a first step.