Package

Awobaz Compoships

Laravel relationships with support for composite/multiple keys

Package

awobaz/compoships

View on GitHub →

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.

Awobaz Compoships Related Articles

Compoships: Eloquent Relationships on Multiple Columns image

Compoships: Eloquent Relationships on Multiple Columns

Read article

Pushsilver

Pushsilver is simple invoicing for freelancers and small studios — send polished invoices, automate reminders, and get paid on time without the bloat.

Pushsilver

Let your users buy domains without leaving your app

If your Laravel app gives users a site, a storefront, or a workspace, they’ll eventually want their own domain. The name.com API lets them search, register, and connect one without leaving your product. It’s a clean REST API, so Laravel’s HTTP client is all you need.

Let your users buy domains without leaving your app

PhpStorm

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

PhpStorm

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift