how do you read the guarded id field of a model?

Make only creates an object but does not save it to the database. Therefore you do not get an id.

The primary key will be auto-incremented in the database, so you only know the id after you save the object.

Creating Models

If you want to save automatically you can also directly use the save function:

$NewCustomer = factory(Customer::class)->create();

This work the same as:

$newCustomer = factory(Customer::class)->make();
$newCustomer->save();

Persisting Models

Also guarded is only a security feature for mass-assignment and prevents saving the id row on those.

Mass Assignment

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top