Polyscope - The agent-first dev environment for Laravel

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.


Awobaz Compoships Related Articles

Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Shift logo

Shift

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

Shift
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
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
PhpStorm logo

PhpStorm

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

PhpStorm