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

Morphism Laravel Package

cline/morphism

Central registry for Laravel polymorphic key mapping. Define which primary key column (id/uuid/ulid) each model uses in morph relations, with migration macros, optional strict enforcement, and config-based setup—ideal for package authors.

View on GitHub
Deep Wiki
Context7

Reusable polymorphic key mapping for Laravel packages. Provides a central registry to manage which primary key column (id, uuid, ulid) each model uses in polymorphic relationships.

Frequently asked questions about Morphism
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.
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
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