feat(laravel): Support composite identifiers/keys within Link
#7342
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem Statement
In PR #7231, we introduced link handling using native Eloquent relationships, which significantly improved support for Laravel's dynamic relationships. However, a limitation emerged when working with composite keys and alternative identifiers.
Current Issue: While composite keys aren't natively supported in Laravel ([reference](#7231)), this shouldn't prevent us from using alternative identifiers for entity lookup, particularly client-facing identifiers.
Use Case Example
Consider a common scenario where:
bigint
primary IDs for internal model relationshipsreference_id
column containing UUIDs for all public lookups/IRIsSolution
This PR introduces intelligent identifier resolution that checks whether we're using the model's primary key or an alternative identifier.
Code Changes
Before (Existing Implementation):
After (New Implementation):
How It Works
getKeyName()
), we maintain the existing behavior for optimal performancereference_id
), we query the database to locate the correct model instanceBenefits
Backward Compatibility
✅ Fully backward compatible - no breaking changes
✅ Existing functionality preserved - primary key lookups use the same fast path
✅ API unchanged - no modifications to public interfaces
This enhancement allows for more flexible identifier strategies while maintaining full compatibility with existing implementations.