Permalink
Browse files

Implement withErrors($validator) for views

  • Loading branch information...
jcoetzee committed Nov 11, 2013
1 parent 9dceadc commit 3c5ca1a85dce7fc915c19b3cd197ad03433375b6
Showing with 22 additions and 0 deletions.
  1. +22 −0 src/Illuminate/View/View.php
@@ -1,7 +1,9 @@
<?php namespace Illuminate\View;
use ArrayAccess;
use Illuminate\Support\MessageBag;
use Illuminate\View\Engines\EngineInterface;
use Illuminate\Support\Contracts\MessageProviderInterface;
use Illuminate\Support\Contracts\ArrayableInterface as Arrayable;
use Illuminate\Support\Contracts\RenderableInterface as Renderable;
@@ -140,6 +142,26 @@ public function with($key, $value = null)
return $this;
}
/**
* Add validation errors to the view.
*
* @param \Illuminate\Support\Contracts\MessageProviderInterface|array $provider
* @return \Illuminate\View\View
*/
public function withErrors($provider)
{
if ($provider instanceof MessageProviderInterface)
{
$this->with('errors', $provider->getMessageBag());
}
else
{
$this->with('errors', new MessageBag((array) $provider));
}
return $this;
}
/**
* Add a view instance to the view data.

0 comments on commit 3c5ca1a

Please sign in to comment.