Created
December 5, 2018 07:45
-
-
Save daison12006013/48be02bd0049b0caea53553de08d0084 to your computer and use it in GitHub Desktop.
Laravel custom error outside Form Request or Validator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Daison\Utils; | |
use Illuminate\Support\MessageBag; | |
use Illuminate\Contracts\Validation\Validator as ValidatorContract; | |
class CustomError implements ValidatorContract | |
{ | |
/** | |
* $messages | |
* | |
* @var array | |
*/ | |
protected $messages; | |
/** | |
* __construct | |
* | |
* @param mixed $messages | |
* @return void | |
*/ | |
public function __construct($messages) | |
{ | |
$this->messages = $messages; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function errors() | |
{ | |
return $this->getMessageBag(); | |
} | |
/** | |
* getMessageBag | |
* | |
* @return void | |
*/ | |
public function getMessageBag() | |
{ | |
return new MessageBag($this->messages); | |
} | |
public function validate() {} | |
public function fails() {} | |
public function failed() {} | |
public function sometimes($attribute, $rules, callable $callback) {} | |
public function after($callback) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment