diff --git a/laravel/messages.php b/laravel/messages.php index 5ca75a6a..16b4fa37 100644 --- a/laravel/messages.php +++ b/laravel/messages.php @@ -9,6 +9,13 @@ class Messages { */ public $messages; + /** + * Default format for message output. + * + * @var string + */ + public $format = ':message'; + /** * Create a new Messages instance. * @@ -68,6 +75,21 @@ public function has($key = null) return $this->first($key) !== ''; } + /** + * Set the default message format for output. + * + * + * // Apply a new default format. + * $messages->set_format('email', '

this is my :message

'); + *
+ * + * @param string $format + */ + public function set_format($format = ':message') + { + $this->format = $format; + } + /** * Get the first message from the container for a given key. * @@ -86,8 +108,9 @@ public function has($key = null) * @param string $format * @return string */ - public function first($key = null, $format = ':message') + public function first($key = null, $format = null) { + $format = ($format === null) ? $this->format : $format; $messages = is_null($key) ? $this->all($format) : $this->get($key, $format); return (count($messages) > 0) ? $messages[0] : ''; @@ -108,8 +131,9 @@ public function first($key = null, $format = ':message') * @param string $format * @return array */ - public function get($key, $format = ':message') + public function get($key, $format = null) { + $format = ($format === null) ? $this->format : $format; if (array_key_exists($key, $this->messages)) { return $this->format($this->messages[$key], $format); @@ -132,8 +156,9 @@ public function get($key, $format = ':message') * @param string $format * @return array */ - public function all($format = ':message') + public function all($format = null) { + $format = ($format === null) ? $this->format : $format; $all = array(); foreach ($this->messages as $messages)