/** * Generate a token to authenticate a user * * @return mixed */ public function login($device_id = null, $device_type = null, $device_token = null) { // clear old sessions for any user with: same(device_id, os) $to_remove = Token::where('device_id', '=', $device_id)->where('device_os', '=', $device_type)->delete(); $token = Token::getInstance(); $token->user_id = $this->_id; $token->device_id = $device_id; $token->device_os = $device_type; $token->device_token = $device_token; $token->save(); return $token; }