2017 © Pedro Peláez
 

library eloquent-composite-primary-keys

Offers composite primary keys on Eloquent models

image

coenjacobs/eloquent-composite-primary-keys

Offers composite primary keys on Eloquent models

  • Monday, October 23, 2017
  • by coenjacobs
  • Repository
  • 4 Watchers
  • 13 Stars
  • 3,530 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 3 Forks
  • 2 Open issues
  • 2 Versions
  • 78 % Grown

The README.md

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., (*1)

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., (*2)

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., (*3)

In case you still want to use this functionality in Laravel, you can have a look at the LaravelTreats package which contains similar functionality., (*4)

Install

Install this package through Composer:, (*5)

composer require coenjacobs/eloquent-composite-primary-keys

Make sure you have a database schema that supports composite primary keys, for example via a migration:, (*6)

Schema::create('products', function (Blueprint $table) {
    $table->integer('first_key');
    $table->integer('another_key');
    $table->primary(['first_key', 'another_key']);
    $table->timestamps();
});

Use the trait on the Eloquent model you wish to have composite primary keys on:, (*7)

namespace App;

use Illuminate\Database\Eloquent\Model;
use CoenJacobs\EloquentCompositePrimaryKeys\HasCompositePrimaryKey;

class Product extends Model
{
    use HasCompositePrimaryKey;

Next, you set the $primaryKey property on your Eloquent model to an array containing the field names that together form your composite primary key:, (*8)

protected $primaryKey = array('first_key', 'another_key');

The Versions

23/10 2017

dev-master

9999999-dev

Offers composite primary keys on Eloquent models

  Sources   Download

MIT

The Requires

 

by Coen Jacobs

23/10 2017

1.0.0

1.0.0.0

Offers composite primary keys on Eloquent models

  Sources   Download

MIT

The Requires

 

by Coen Jacobs