Framework: Model::create returns Model with id=0

Created on 13 Jun 2014  ·  3Comments  ·  Source: laravel/framework

When I create a model it returns a model with id set to 0

$key = Key::create(array(
    'id' => 'someKey',
    'valid_till' => new DateTime('now +2hours'),
    'user_id' => 1
));
var_dump($key->id); // int(0)

Note that the id-field is not auto increnment but primary. Furtermore id is a string in the database and should never be int

The Model:

class Key extends Eloquent{
protected $table = 'keys';
    protected $guarded = [];
}

The Schema

$table->string('id')->primary();
$table->dateTime('valid_till');
$table->timestamps();
$table->integer('user_id');

I'm using laravel 4.2.2

Most helpful comment

you need to set the auto incrementing property on your model to false.

All 3 comments

The Schemale

I do not think it means what you think it means.

lol - I have no Idea how a wrong written "Schema" could transform to this :D. I will change it^^

you need to set the auto incrementing property on your model to false.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PhiloNL picture PhiloNL  ·  3Comments

klimentLambevski picture klimentLambevski  ·  3Comments

felixsanz picture felixsanz  ·  3Comments

Anahkiasen picture Anahkiasen  ·  3Comments

jackmu95 picture jackmu95  ·  3Comments