PHP Classes


Recommend this page to a friend!
  Classes of Thiago Przyczynski   Eloquent Composite Primary Key   Download  
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: 2 years ago
Size: 608 bytes


Class file image Download

Eloquent Composite Key

Package to enable composite key support on Eloquent Models.


Install it with composer:

composer require thiagoprz/eloquent-composite-key


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