Download the PHP package coenjacobs/eloquent-composite-primary-keys without Composer
On this page you can find all versions of the php package coenjacobs/eloquent-composite-primary-keys. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download coenjacobs/eloquent-composite-primary-keys
More information about coenjacobs/eloquent-composite-primary-keys
Files in coenjacobs/eloquent-composite-primary-keys
Package eloquent-composite-primary-keys
Short Description Offers composite primary keys on Eloquent models
License MIT
Informations about the package eloquent-composite-primary-keys
Eloquent Composite Primary Keys
A single trait to implement in your Eloquent models to support composite primary keys. The Laravel Schema builder supports creating composite primary keys, but Eloquent models don't support it.
This package is largely inspired by suggested code on Stack Exchange and has also been released in a package with more than this functionality. I needed a separate package for just this purpose.
IMPORTANT: This is now read-only
I have decided to make this project read-only and not further work on this. There are a bunch of performance related downsides when doing this in Laravel, which make it no longer fun and rewarding for me to work on.
In case you still want to use this functionality in Laravel, you can have a look at the LaravelTreats package which contains similar functionality.
Install
Install this package through Composer:
Make sure you have a database schema that supports composite primary keys, for example via a migration:
Use the trait on the Eloquent model you wish to have composite primary keys on:
Next, you set the $primaryKey
property on your Eloquent model to an array containing the field names that together form your composite primary key: