notpurpell / composito
Composito is a small package that gives eloquent models the ability to have composite primary keys.
Requires
- php: ^7.4
- illuminate/database: ^7.0
Requires (Dev)
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2025-07-07 23:50:08 UTC
README
Composito is a small package that gives eloquent models the ability to have composite primary keys through a trait.
Installation
You can install composito
using Composer.
composer require notpurpell/composito
Usage
To add the composite primary key functionality to your eloquent model you must:
- Use the
HasCompositePrimaryKey
trait. - Specify the composite primary key using the
$primaryKey
property. - Set the
$incrementing
property to false.
use Composito\Traits\HasCompositePrimaryKey;
class MyModel extends Eloquent
{
use HasCompositePrimaryKey;
/**
* Indicates if the IDs are auto-incrementing.
* @var bool
*/
public $incrementing = false;
/**
* The composite primary key of the model.
* @var array
*/
protected $primaryKey = [ "primary_one", "primary_two" ];
...
}
Then, you can use the create()
, save()
, update()
, and delete()
methods normally.
Support for other methods such as the find()
method is coming soon.
Tests
The package contains some tests that can be run via phpunit.
./vendor/bin/phpunit
Credits
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.