samedi 19 août 2017

Laravel Eloquent resets primary key value after save() called

I'm using Laravel 5.2 and when I update model, primary key id column is somehow reset to 0. What's happening is below.

$fooModel = FooModel::find(123);
$fooModel->foo_title = 'foo';
echo($fooModel->foo_id); //123
$fooModel->save();
echo($fooModel->foo_id); //0

The data is successfully updated on MySQL database, but foo_id column is reset to 0 in PHP. If it's an autoincrement column, I know it'll be updated by the next sequence value, but this column is not. Is there anything I'm missing?

class FooModel extends Model
{
    protected $table = 'foo_table';
    protected $primaryKey = 'foo_id';
    protected $guarded = ['foo_id'];
    protected $casts = [
        'foo_id' => 'integer'
    ];
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2igXs2P
via IFTTT

Aucun commentaire:

Enregistrer un commentaire