laravel-composite-key icon indicating copy to clipboard operation
laravel-composite-key copied to clipboard

PHP trait to use composite keys in your Laravel Eloquent models.

Laravel Composite Key Trait

This is a small trait that I use in my projects, if I need support for composite keys in my Eloquent models.

Install via composer:

composer require mpociot/laravel-composite-key

Then use the trait in your model:

class MyModel extends Model
{
    use HasCompositeKey;

    protected $primaryKey = ['foo', 'bar'];

}