From 30230b3544a28e783b4d6504ede4e86a3278ab4d Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 25 May 2015 13:22:08 +0200 Subject: Fixed bug in models without auto_increment column --- .../BotleaguesApi/Database/PasswordReminder.php | 1 + src/CamilStaps/BotleaguesApi/Database/User.php | 17 ++++++----------- 2 files changed, 7 insertions(+), 11 deletions(-) (limited to 'src/CamilStaps/BotleaguesApi/Database') diff --git a/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php b/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php index 803d7e8..e0c856a 100644 --- a/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php +++ b/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php @@ -28,6 +28,7 @@ class PasswordReminder extends Model { protected $hidden = ['token']; protected $fillable = ['userEmail', 'token', 'valid_till']; protected $primaryKey = 'token'; + public $incrementing = false; public static function boot() { parent::boot(); diff --git a/src/CamilStaps/BotleaguesApi/Database/User.php b/src/CamilStaps/BotleaguesApi/Database/User.php index c0a25b0..017f0e2 100644 --- a/src/CamilStaps/BotleaguesApi/Database/User.php +++ b/src/CamilStaps/BotleaguesApi/Database/User.php @@ -35,6 +35,7 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon protected $hidden = ['password', 'remember_token', 'api_key']; protected $fillable = ['email', 'password']; protected $primaryKey = 'email'; + public $incrementing = false; public function isAdministrator() { return (bool) $this->isAdministrator; @@ -117,26 +118,20 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon } public function setEmailAttribute($email) { - $rules = [ - 'email' => ['required', 'email', 'unique:' . $this->table] - ]; - $validator = Validator::make(['email' => $email], $rules); + $validator = Validator::make(['email' => $email], ['email' => ['required', 'email', 'unique:' . $this->table]]); if ($validator->fails()) { - throw new ValidationException('Invalid input', $validator->errors()); + throw new ValidationException('Invalid input email', $validator->errors()); } - $this->attributes['email'] = $email; + return $this->attributes['email'] = $email; } public function setPasswordAttribute($password) { - $rules = [ - 'password' => ['required', 'min:7'] - ]; - $validator = Validator::make(['password' => $password], $rules); + $validator = Validator::make(['password' => $password], ['password' => ['required', 'min:7']]); if ($validator->fails()) { throw new ValidationException('Invalid input', $validator->errors()); } - $this->attributes['password'] = Hash::make($password); + return $this->attributes['password'] = Hash::make($password); } } \ No newline at end of file -- cgit v1.2.3