1

My book table's primary key is called ISBN.

book table's pk

But when I try to update others columns using the ISBN I get the following error:

ISBN

I can fix it changing the eloquent query, but I want to know why this mistake appears.

Thanks in advance!

Álvaro
  • 385
  • 5
  • 15

1 Answers1

6

Laravel automatically converts the names of relationships from camelCase to snake_case when the model is converted to an array (toArray()) or json (toJson()).

to avoid this changes write this line in your model:

public static $snakeAttributes = false;

see:

https://stackoverflow.com/a/44794070/10573560

OMR
  • 11,736
  • 5
  • 20
  • 35
  • 1
    It doesn't work. I'm still having the same error. I tried to write the line you give me and the primary key in the model. – Álvaro May 14 '20 at 12:54
  • please write the query witch made the error in your question – OMR May 14 '20 at 12:56
  • sorry to be late, after long research, it was obvious that it's laravel convention, so tweak it would take some effort, – OMR May 16 '20 at 20:51
  • you had to make you own model class, like in this answer: https://stackoverflow.com/a/33710995/10573560 – OMR May 16 '20 at 20:51