PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Thiago Przyczynski   Eloquent Composite Primary Key   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: Eloquent Composite Primary Key
Define object properties to use as primary keys
Author: By
Last change:
Date: 3 years ago
Size: 608 bytes
 

Contents

Class file image Download

Eloquent Composite Key

Package to enable composite key support on Eloquent Models.

Installation

Install it with composer:

composer require thiagoprz/eloquent-composite-key

Usage

Define the primaryKey as an array and use the HasCompositeKey trait on your model.

class User extends Model 
{
    use HasCompositeKey;
    ...
    protected $primaryKey = ['firstKey', 'secondKey'];
    ...
}

The idea of this package is to allow eloquent models to use composite keys despite that Eloquent doesn't support it officially (see https://laravel.com/docs/8.x/eloquent#composite-primary-keys).