Laravel: how to recover the primary key of a model after saving it [closed]

1

I wonder if it is possible to retrieve the ID of a template at the time it is saved to the database. I'm using the following Eloquent method:

$modelo = Modelo::create(['ATT1' => 'valor1', 'ATT2'=>'valor2']);

The template is saved, but the primary key is not returned in the $ model variable. Am I doing it right or is something wrong?

    
asked by anonymous 18.08.2017 / 15:41

1 answer

1

I usually do the following, using your example would look like this:

$modelo = Modelo::create(['ATT1' => 'valor1', 'ATT2'=>'valor2']);

return $modelo->id;

If the primary key is named id would look like this.

    
18.08.2017 / 15:45