UUID primary key in Eloquent model is stored as uuid but returns as 0 : <p>I have a mysql table in which I'm using a UUID as the primary key. Here's the creation migration:</p>

<pre><code>Schema::create('people', function (Blueprint $table) {
    $table-&gt;uuid('id');
    $table-&gt;primary('id');
    ...
    $table-&gt;timestamps();
}
</code></pre>

<p>Which generates the following MySQL schema:</p>

<pre><code>CREATE TABLE `people` (
  `id` char(36) COLLATE utf8_unicode_ci NOT NULL,
  ...
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
</code></pre>

<p>In my Eloquent model I have a method for creating an instance which calls a method for generating the UUID:</p>

<pre><code>class Person extends Model
{
    protected $fillable = [
        ...
    ];

    public function make(array $personData){
        $person = new Person;
        $person-&gt;setUUID();
        collect($personData)-&gt;each(function ($value, $columnName) use($person){
            if(in_array($columnName, $this-&gt;fillable)){
                $person-&gt;{$columnName} = $value;
            }
        });
        $person-&gt;save();
        return $person;
    }

    protected function setUUID(){
        $this-&gt;id = preg_replace('/\./', '', uniqid('bpm', true));
    }

}
</code></pre>

<p>When I create a new model instance it stores it fine in the database:</p>

<p><a href="https://i.stack.imgur.com/ZMQ2V.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ZMQ2V.png" alt="uuids stored"></a></p>

<p>But when I try to access the new instance's id:</p>

<p><a href="https://i.stack.imgur.com/CVvHU.png" rel="noreferrer"><img src="https://i.stack.imgur.com/CVvHU.png" alt="creating new instance and dumping id"></a></p>

<p>It returns as 0:</p>

<p><a href="https://i.stack.imgur.com/wr0or.png" rel="noreferrer"><img src="https://i.stack.imgur.com/wr0or.png" alt="returned result"></a></p>

<p>What am I missing here?</p>
