laravel uuid not showing in query
Eloquent makes the assumption that the primary key (which is named id
by default) is an integer, and it casts it to int
by default in the getCasts
method:
public function getCasts(){ if ($this->incrementing) { return array_merge([ $this->getKeyName() => 'int', ], $this->casts); } return $this->casts;}
This can be overwritten by specifying that the primary key is not auto incrementing by adding this to your model:
$incrementing = false;
Or by casting the id
column to string
in the $casts
property of the model, like so:
protected $casts = [ 'id' => 'string']
As described in the Eloquent: Attribute Casting documentation.