Authored by ziy

添加方法first

@@ -63,11 +63,27 @@ class Messages @@ -63,11 +63,27 @@ class Messages
63 * 判断是否有错误信息 63 * 判断是否有错误信息
64 * @return bool 64 * @return bool
65 */ 65 */
66 - public function has() 66 + public function has($key = null)
67 { 67 {
  68 + if ($key == null) {
  69 + return count($this->messages) > 0;
  70 + }
68 return isset($this->messages[$key]); 71 return isset($this->messages[$key]);
69 } 72 }
70 73
  74 + /**
  75 + * 第一个错误
  76 + * @param $key
  77 + * @return array
  78 + */
  79 + public function first($key)
  80 + {
  81 + if (isset($this->messages[$key])) {
  82 + return $this->messages[$key][0];
  83 + }
  84 + return '';
  85 + }
  86 +
71 public function getMessages($key, $type = null) 87 public function getMessages($key, $type = null)
72 { 88 {
73 if (isset($this->customMessages[$key])) { 89 if (isset($this->customMessages[$key])) {