From 6b73974505557c9663f9f6cbc00793d3225c9d20 Mon Sep 17 00:00:00 2001 From: Callum McIntyre Date: Mon, 3 Sep 2012 21:44:16 +0100 Subject: [PATCH] Added new touch function to eloquent, updates timestamps and immediately saves Signed-off-by: Callum McIntyre --- laravel/database/eloquent/model.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/laravel/database/eloquent/model.php b/laravel/database/eloquent/model.php index 306d471a..c2566496 100644 --- a/laravel/database/eloquent/model.php +++ b/laravel/database/eloquent/model.php @@ -452,6 +452,16 @@ abstract class Model { if ( ! $this->exists) $this->created_at = $this->updated_at; } + /** + *Updates the timestamp on the model and immediately saves it. + * + * @return void + */ + public function touch(){ + $this->timestamp(); + $this->save(); + } + /** * Get a new fluent query builder instance for the model. *