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)    
Last Updated Ratings Unique User Downloads Download Rankings
2021-03-25 (24 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 30 This week: 2All time: 10,153 This week: 148Up
Version License PHP version Categories
eloquent-composite-k 1.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
Nominee
Vote
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: 10 packages by
Country: Brazil Brazil
Innovation award
Innovation award
Nominee: 5x

Details

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:30
This week:2
All time:10,153
This week:148Up

For more information send a message to info at phpclasses dot org.