本文整理汇总了PHP中Illuminate\Validation\Validator::errors方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::errors方法的具体用法?PHP Validator::errors怎么用?PHP Validator::errors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Validation\Validator
的用法示例。
在下文中一共展示了Validator::errors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: error
public function error()
{
if ($this->validator->errors()) {
return $this->validator->errors()->first();
}
return null;
}
示例2: callCustomCallback
/**
* Call the custom plan eligibility checker callback.
*
* @param \Illuminate\Validation\Validator $validator
* @param \Laravel\Spark\Plan $plan
* @return void
*/
protected function callCustomCallback($validator, $plan)
{
try {
if (!Spark::eligibleForTeamPlan($this->route('team'), $plan)) {
$validator->errors()->add('plan', 'This team is not eligible for this plan.');
}
} catch (IneligibleForPlan $e) {
$validator->errors()->add('plan', $e->getMessage());
}
}
示例3: runValidation
/**
* Validates the model.
*
* @param array $customRules
* @param array $customMessages
* @param array $attributeNames
*
* @return bool
*/
protected function runValidation(array $customRules = [], array $customMessages = [], array $attributeNames = [])
{
$rules = empty($customRules) ? $this->getRules() : $customRules;
$messages = empty($customMessages) ? $this->getCustomMessages() : $customMessages;
$attributeNames = empty($attributeNames) ? $this->getAttributeNames() : $attributeNames;
$attributes = $this->prepareAttributes();
$this->validator = $this->makeValidator($attributes, $rules, $messages);
$this->validator->setAttributeNames($attributeNames);
$success = $this->validator->passes();
if (!$success) {
$this->setErrors($this->validator->errors());
}
return $success;
}
示例4: __construct
/**
* ValidationException constructor.
*
* @author Morten Rugaard <moru@nodes.dk>
* @param \Illuminate\Validation\Validator $validator
* @param array $errorCodes
* @param array $headers
* @param bool $report
* @param string $severity
*/
public function __construct(IlluminateValidator $validator, array $errorCodes, array $headers = [], $report = false, $severity = 'error')
{
// Parse failed rules
$failedRules = $this->parseFailedRules($validator->failed());
// Set message of exception
$errorMessages = $validator->errors();
if ($errorMessages->count() > 1) {
$message = 'Multiple validation rules failed. See "errors" for more details.';
} else {
$message = $errorMessages->first();
}
// Custom error codes container
$customErrorCodes = [];
// Custom error codes takes priority, so let's see
// if one of our failed rules has one
$failedRulesCustomErrorCodes = array_intersect(array_keys($errorCodes), $failedRules);
if (!empty($failedRulesCustomErrorCodes)) {
foreach ($failedRulesCustomErrorCodes as $failedRule) {
$customErrorCodes[$errorCodes[$failedRule]] = $errorCodes[$failedRule];
}
}
// Determine exception and status code
$exceptionCode = $statusCode = !empty($customErrorCodes) ? array_shift($customErrorCodes) : 412;
// Construct exception
parent::__construct($message, $exceptionCode, $headers, $report, $severity);
// Fill exception's error bag with validation errors
$this->setErrors($errorMessages);
// Set status code
$this->setStatusCode($statusCode, $errorMessages->first());
// Do not send report
$this->dontReport();
}
示例5: fieldHasError
/**
* Check if a field has any errors
*
* @param $field
* @return mixed
*/
public function fieldHasError($field)
{
if (!isset($this->validator)) {
$this->validate();
}
return isset($this->validator->errors()->getMessages()[$field]);
}
示例6: __construct
public function __construct(Validator $validator)
{
$errors = '';
foreach ($validator->errors()->getMessages() as $key => $messages) {
$errors .= implode(' ', $messages) . ' ';
}
parent::__construct(422, trim($errors));
}
示例7: formatErrors
protected function formatErrors(Validator $validator)
{
$errors = $this->parseErrorRest($validator->errors()->getMessages());
$response = new ResponseWService();
$response->setDataResponse(ResponseWService::HEADER_HTTP_RESPONSE_SOLICITUD_INCORRECTA, array(), $errors, 'Datos Invalidos del formulario');
$response->response();
// return $validator->errors()->all();
}
示例8: validateMaximumTeamsNotExceeded
/**
* Validate that the maximum number of teams hasn't been exceeded.
*
* @param \Illuminate\Validation\Validator $validator
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return void
*/
protected function validateMaximumTeamsNotExceeded($validator, $user)
{
if (!($plan = $user->sparkPlan())) {
return;
}
if (is_null($plan->teams)) {
return;
}
if ($plan->teams <= $user->ownedTeams()->count()) {
$validator->errors()->add('name', 'Please upgrade your subscription to create more teams.');
}
}
示例9: appendErrors
public static function appendErrors(\Illuminate\Validation\Validator $validator)
{
foreach ($validator->errors()->all() as $message) {
Session::push('field_validation_errors', $message);
}
}
示例10: validateLocation
/**
* Validate that the request's location information agrees.
*
* @param \Illuminate\Validation\Validator $validator
* @return void
*/
protected function validateLocation($validator)
{
if (!app(StripeService::class)->tokenIsForCountry($this->stripe_token, $this->country)) {
$validator->errors()->add('country', 'This country does not match the origin country of your card.');
}
}
示例11: formatErrors
protected function formatErrors(Validator $validator)
{
Session::flash('am-alert', ['type' => 'warning', 'data' => array_values($validator->errors()->all())]);
return $validator->errors()->all();
}
示例12: formatValidationErrors
protected function formatValidationErrors(Validator $validator)
{
return $validator->errors()->all('<li>:message</li>');
}
示例13: validator
/**
* Set error messages from a validator instance.
*
* @param Validator
*
* @return $this
*/
public function validator(Validator $validator)
{
$this->attributes['message'] = $validator->errors()->all();
return $this;
}
示例14: formatValidationErrors
/**
* {@inheritdoc}
*/
protected function formatValidationErrors(Validator $validator)
{
return ['errno' => 1, 'msg' => $validator->errors()->first()];
}
示例15: formatValidationErrors
protected function formatValidationErrors(Validator $validator)
{
$errors = ['status' => 400, 'errors' => $validator->errors()->getMessages()];
return $errors;
}