Compoships

awobaz/compoships image

Compoships stats

Downloads
3.9M
Stars
2
Open Issues
1
Forks
1

View on GitHub →

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, and belongsTo relationships.

Installation

Install Compoships via Composer:

composer require awobaz/compoships

Usage

To utilize Compoships, you can either:

  1. Extend your model from Awobaz\Compoships\Database\Eloquent\Model
  2. Use the Awobaz\Compoships\Compoships trait 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.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Awobaz Compoships Related Articles

SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Celebian logo

Celebian

Celebian is a social media marketing agency specializing in helping their clients go viral on TikTok. Whether you're looking to reach a bigger audience or gain more Tiktok followers, likes, and views, they've got you covered.

Celebian
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Honeybadger logo

Honeybadger

Simple developer-focused application monitoring for Laravel. Error tracking, log management, uptime monitoring, status pages, and more!

Honeybadger
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm