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.

Cube

Laravel Newsletter

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


Awobaz Compoships Related Articles

LoadForge logo

LoadForge

Scalable load testing for web apps & APIs. Simulate real-world traffic and identify breaking points and performance limits with powerful, scalable load tests designed for Laravel.

LoadForge
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Acquaint Softtech logo

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
Blastup logo

Blastup

Blastup provides social media enhancement services including buying Instagram likes, followers, and views, with features like instant delivery and a variety of packages to suit different needs.

Blastup
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
DreamzTech logo

DreamzTech

Hire 6-10+ Yrs. experienced skilled Laravel Developers from DreamzTech. We ensure NDA protected, 100% quality delivery. Contact Us & Discuss Your Need.

DreamzTech