orm - Laravel Eloquent last inserted object wrong properties -
i've got problem while using laravel eloquent orm: when inserting new eloquent model in database, data corrupted. concrete:
$newitem = new notificationnewitem; $newitem->item_id = $item->id; // item_id primary key (returned getkeyname()) $newitem->save(); return notificationnewitem::find($item->id);
this code not return same
$newitem = new notificationnewitem; $newitem->item_id = $item->id; $newitem->save(); return $newitem;
whereas 2 items should same, shouldn't ? weird part returned json object (i show directly in browser) in first case inserted in database, , in second case json object's primary key (here item_id) equal 0 if in database corresponding entry has primary key equal 3 (or different values).
here's laravel code if want see error again : http://pastebin.com/9wcsnvsq there 2 "returns" in model function insertandgetelement() , return items different primary keys (the first 1 in pastebin returning primary key equal 0).
help appreciated. in advance, robin.
the solution problem (primary key set 0 after calling save()) precisely define model not auto_incrementing primary key. so, use
public $incrementing = false;
in model declaration. andreaslutro on #laravel!
Comments
Post a Comment