Compoships
Compoships stats
- Downloads
- 3.9M
- Stars
- 2
- Open Issues
- 1
- Forks
- 1
Laravel relationships with support for composite/multiple keys
Compoships: Multi-Column Relationships in Laravel Eloquent
Compoships is a Laravel package designed to enhance Eloquent by allowing developers to define relationships based on multiple columns. This is particularly useful when dealing with legacy databases or schemas where composite keys define relationships.
Key Features
- Multi-Column Relationships: Easily define Eloquent relationships using two or more columns without altering the core functionality of Eloquent.
- Ease of Integration: Integrate by either extending the custom model class provided by Compoships or using the trait in existing models.
- Supported Relationships: Includes support for
hasOne,hasMany, andbelongsTorelationships.
Installation
Install Compoships via Composer:
composer require awobaz/compoships
Usage
To utilize Compoships, you can either:
- Extend your model from
Awobaz\Compoships\Database\Eloquent\Model - Use the
Awobaz\Compoships\Composhipstrait in your existing model.
Here’s a quick example to define a relationship:
namespace App; use Illuminate\Database\Eloquent\Model; class A extends Model{ use \Awobaz\Compoships\Compoships; public function b() { return $this->hasMany('B', ['f1', 'f2'], ['f1', 'f2']); }}
Important Notes
- Compatibility: Compoships is tailored for Laravel 5’s Eloquent and does not support composite keys but allows defining relationships using multiple columns.
- Versioning: Compoships follows Semantic Versioning. For available versions, check the repository tags.
Contributing
Developers are encouraged to contribute to the project by following the guidelines outlined in the project's CONTRIBUTING.md file.
Running Tests
To run the test suite:
$ composer install --dev$ vendor/bin/phpunit
Summary
Compoships is an essential tool for developers working with complex database schemas in Laravel, providing flexibility in defining relationships across multiple columns. It simplifies the management of legacy databases and enhances Laravel's Eloquent without compromising its core functionality.