Why does Eloquent (in Laravel) change my varchar uuid primary key to an integer ?

Laravel model default type of it’s id is integer, so if we want to use varchar as primary key we need to specify the type in our model.

Add this following code into respective model that use varchar as it’s primary key

protected $casts = [
  'id' => 'string'
];

Then check it again, the varchar uuid will shown as it’s primary key in response

Leave a Comment