5 years ago

How to reference Composite Key in Models?

Posted 5 years ago by mikebronner

OK, so I set up my table using schema builder with a composite primary key using the following hypothetical:

            $table->primary(['age', 'height', 'weight', 'shoeSize']);

Now, since 'id' field does not exist, I need to tell my model what to use as a primary key?

class Individual extends \Eloquent
    protected $primaryKey = ????;

Do I tell it to use an array, like $primaryKey = ['age', 'height', 'weight', 'shoeSize'];?

Please sign in or create an account to participate in this conversation.