PHP Classes

Eloquent Composite Primary Key: Define object properties to use as primary keys

Recommend this page to a friend!
  Info   View files Documentation   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 44 This week: 1All time: 10,758 This week: 560Up
Version License PHP version Categories
eloquent-composite-k 1.0.0MIT/X Consortium ...5PHP 5, Databases, Libraries, Design P...
Description 

Author

This package can be used to define object properties to use as primary keys.

It provides a trait that can be used in Laravel model classes to define multiple properties that will be used as primary keys.

The names of the primary key properties should be defined in model classes as an array assigned to a primary class protected class variable.

Innovation Award
PHP Programming Innovation award nominee
March 2021
Number 10
Usually applications that database tables to store information, define one field that has unique values in all records to be the key to access the record data faster.

However, in certain applications there is the need to use more than one table field as unique value key to access the table records faster.

This package provides a trait that can be used with Laravel model objects to define which fields will be used as primary keys composed with values of more than one field.

Manuel Lemos
Picture of Thiago Przyczynski
  Performance   Level  
Name: Thiago Przyczynski <contact>
Classes: 16 packages by
Country: Brazil Brazil
Age: 34
All time rank: 3203238 in Brazil Brazil
Week rank: 106 Up7 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 8x

Documentation

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).


  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file HasCompositeKey.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:44
This week:1
All time:10,758
This week:560Up