notpurpell / composito
Composito is a small package that gives eloquent models the ability to have composite primary keys.
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/notpurpell/composito
Requires
- php: ^7.4
- illuminate/database: ^7.0
Requires (Dev)
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2025-12-08 00:37:42 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
HasCompositePrimaryKeytrait. - Specify the composite primary key using the
$primaryKeyproperty. - Set the
$incrementingproperty 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.