So I've read the Laravel documentation on Eloquent and how it assumes that the table has a primaryKey called id.
I currently have a id
field in the table that is auto-incrementing
however, it is not a primary key
. I have a composite primary key
which eloquent doesn't fully support. This is not a huge issue for me. I don't mind working with the id
field that is auto-incrementing.
I am just wondering if Eloquent
will be able to work with id
key even though it is not a primary key
, but a auto incrementing
one.
You may use any custom primary key in your table
but only thing you need to explicitly declare the PK
in the model, for example:
protected $primaryKey = 'custom_pk';
It'll work without any problem even when there is an id
(non primary key) field in the table.