From 77e10d25829f3523a168bf61424fac99a539f8be Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sat, 22 Nov 2014 18:22:10 -0500 Subject: Improve API to return id instead of a boolean --- app/Model/User.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'app/Model/User.php') diff --git a/app/Model/User.php b/app/Model/User.php index 41bad0bb..3dd5993d 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -255,12 +255,20 @@ class User extends Base * * @access public * @param array $values Form values - * @return boolean + * @return boolean|integer */ public function create(array $values) { $this->prepare($values); - return $this->db->table(self::TABLE)->save($values); + + return $this->db->transaction(function($db) use ($values) { + + if (! $db->table(User::TABLE)->save($values)) { + return false; + } + + return (int) $db->getConnection()->getLastId(); + }); } /** -- cgit v1.2.3