3
votes

Laravel has two timestamps on every table(created_at and updated_at). I thought it would insert created_at at insertion of new row and update updated_at at update. However what happens is that created_at field is getting an update when I update my model.

How do I alter this behavior or what method should I use to update a row and just updated_at timestamp? Right now I use $model->save();

 $point = Map::find($id);
        $point->longitude = $request->longitude;
        $point->latitude = $request->latitude;
        $point->description = $request->description;
        $point->save();
1
Would you please show me some of you code that you use for updating the model? - mininoz
The code you've shown wouldn't be causing created_at to be updated on an existing model. - ceejayoz
Do you have any mutators setup on your model which could be causing this? For example a setCreatedAtAttribute($value) method? - user1669496
No, all I have done was extending the model class - zarcel

1 Answers

2
votes

I found a solution to my problem. I created created_at and updated_at columns manually and created_at had on Update assign current_timestamp attribute.