mr-punyapal/laravel-extended-relationships
Adds efficient, extended Eloquent relationship helpers for Laravel models to cut queries, boost performance, and reduce duplicate code. Includes a HasExtendedRelationships trait and custom relations like belongsToManyKeys. Compatible with Laravel 11–13 and PHP 8.2+.
Strengths:
belongsToManyKeys) into single queries, reducing database load. Ideal for high-traffic features (e.g., audit logs, hierarchical data).hasManyArrayColumn, BelongsToArrayColumn), reducing boilerplate and accelerating feature delivery.Weaknesses:
hasMany/belongsTo relationships; better suited for multi-relationship patterns (e.g., audit trails, tagging).Pros:
composer require mrpunyapal/laravel-extended-relationships). No database migrations or schema changes required.hasMany, belongsToMany) without conflicts.Cons:
php artisan boost:install.belongsToManyKeys) may confuse teams unfamiliar with the package’s patterns.hasManyArrayColumn with large arrays) could introduce latency if not benchmarked.Low Risk:
Moderate Risk:
belongsToManyKeys or hasManyArrayColumn could lead to unintended joins or memory issues with large datasets. Requires benchmarking in staging.isString flag) may require custom validation logic for production data.High Risk (Mitigable):
foreignKey) could cause silent failures. Solution: Add runtime validation in tests.Use Case Validation:
Team Readiness:
Performance Impact:
hasManyArrayColumn, test with large arrays (e.g., 100+ IDs) to ensure no timeouts.Migration Strategy:
created_by columns) be refactored to use belongsToManyKeys? Prioritize low-risk features first.Long-Term Viability:
Ideal For:
Less Suitable For:
Assessment Phase (1–2 weeks):
Pilot Implementation (2–4 weeks):
composer require mrpunyapal/laravel-extended-relationships laravel/boost --dev
php artisan boost:install
php artisan boost:update --discover
Post) to use belongsToManyKeys for audit relationships:
use MrPunyapal\LaravelExtendedRelationships\HasExtendedRelationships;
class Post extends Model {
use HasExtendedRelationships;
public function auditors() {
return $this->belongsToManyKeys(
related: User::class,
foreignKey: 'id',
relations: [
'created_by' => 'creator',
'updated_by' => 'updater',
]
);
}
}
Gradual Rollout (4–8 weeks):
$post->auditors->creator).Full Adoption (Ongoing):
hasManyArrayColumn for tagging).belongsToManyKeys for audit trails").Cache::remember). Ensure cached queries include the new relationships.1
How can I help you explore Laravel packages today?