本文整理汇总了PHP中Illuminate\Contracts\Validation\Validator类的典型用法代码示例。如果您正苦于以下问题:PHP Validator类的具体用法?PHP Validator怎么用?PHP Validator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Validator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: formatErrors
protected function formatErrors(Validator $validator)
{
if (count($validator->errors()->getMessages()) > 8) {
return [trans('messages.many-errors')];
}
return $validator->errors()->all();
}
示例2: formatErrors
public function formatErrors(Validator $validator)
{
$repeatedAttendee = false;
$emptyNames = false;
$errors = $validator->errors()->all();
foreach ($errors as $index => $error) {
if (fnmatch('The selected user id.* is invalid.', $error)) {
// Removes from array; can still iterate through array with foreach
unset($errors[$index]);
$repeatedAttendee = true;
} else {
if (fnmatch('The name.* field is required.', $error)) {
unset($errors[$index]);
$emptyNames = true;
}
}
}
// Pushes more descriptive error message onto array
if ($repeatedAttendee) {
array_push($errors, 'The same attendee has been entered in the attendance list more than once.');
}
if ($emptyNames) {
array_push($errors, 'One of the names of the listed attendees has not been provided.');
}
return $errors;
}
示例3: formatErrors
public function formatErrors(Validator $validator)
{
foreach ($validator->errors()->all() as $error) {
Notifications::add($error, 'danger');
}
return $validator->errors()->getMessages();
}
示例4: failedValidation
/**
* Handle a failed validation attempt.
*
* @param \Illuminate\Contracts\Validation\Validator $validator
*
* @return void
*/
protected function failedValidation(Validator $validator)
{
if ($this->container['request'] instanceof Request) {
throw new ValidationHttpException($validator->errors());
}
parent::failedValidation($validator);
}
示例5: validateWith
/**
* Run the validation routine against the given validator.
*
* @param \Illuminate\Contracts\Validation\Validator $validator
* @param \Illuminate\Http\Request|null $request
* @return void
*/
public function validateWith($validator, Request $request = null)
{
$request = $request ?: app('request');
if ($validator->fails()) {
$this->throwValidationException($request, $validation);
}
}
示例6: failedValidation
/**
* Handle a failed validation attempt.
*
* @param \Illuminate\Contracts\Validation\Validator $validator
*
* @return mixed
*/
protected function failedValidation(Validator $validator)
{
if ($this->container['request'] instanceof BaseRequest) {
throw new ApiValidationException($validator->errors(), $this->getFailedValidationMessage($this->container['request']));
}
parent::failedValidation($validator);
}
示例7: validatePhone
/**
* Validates a phone number.
*
* @param string $attribute
* @param mixed $value
* @param array $parameters
* @param \Illuminate\Contracts\Validation\Validator $validator
* @return bool
* @throws \Propaganistas\LaravelPhone\Exceptions\InvalidParameterException
* @throws \Propaganistas\LaravelPhone\Exceptions\NoValidCountryFoundException
*/
public function validatePhone($attribute, $value, array $parameters, Validator $validator)
{
$this->attribute = $attribute;
$this->data = $validator->getData();
$this->parameters = array_map('strtoupper', $parameters);
$this->determineCountries();
$this->determineTypes();
$this->checkLeftoverParameters();
$phoneUtil = PhoneNumberUtil::getInstance();
// Perform validation.
foreach ($this->allowedCountries as $country) {
try {
// For default countries or country field, the following throws NumberParseException if
// not parsed correctly against the supplied country.
// For automatic detection: tries to discover the country code using from the number itself.
$phoneProto = $phoneUtil->parse($value, $country);
// For automatic detection, the number should have a country code.
// Check if type is allowed.
if ($phoneProto->hasCountryCode() && empty($this->allowedTypes) || in_array($phoneUtil->getNumberType($phoneProto), $this->allowedTypes)) {
// Automatic detection:
if ($country == 'ZZ') {
// Validate if the international phone number is valid for its contained country.
return $phoneUtil->isValidNumber($phoneProto);
}
// Force validation of number against the specified country.
return $phoneUtil->isValidNumberForRegion($phoneProto, $country);
}
} catch (NumberParseException $e) {
// Proceed to default validation error.
}
}
return false;
}
示例8: failedValidationResponse
/**
* Get the response for a error validate.
*
* @param Validator $validator
* @return \Illuminate\Http\Response
*/
public function failedValidationResponse(Validator $validator)
{
if ($this->is('api/*')) {
return \ResponseFractal::respondErrorWrongArgs($validator->errors());
}
return $this->response($this->formatErrors($validator));
}
示例9: 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();
}
示例10: failedValidation
protected function failedValidation(Validator $validator)
{
if ($this->ajax()) {
$this->session()->flashInput($this->all());
$this->session()->flash('errors', $validator->getMessageBag());
}
parent::failedValidation($validator);
}
示例11: throwStoreResourceFailedException
public function throwStoreResourceFailedException($message = 'Failed to store your requested resource.', Validator $validator = null)
{
if ($validator instanceof Validator) {
throw new \Dingo\Api\Exception\StoreResourceFailedException($message, $validator->errors());
} else {
throw new \Dingo\Api\Exception\StoreResourceFailedException($message);
}
}
示例12: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Validator $validator, Request $request)
{
$messages = $validator->errors();
$request->session()->flash('status', 'Task was successful!');
foreach ($messages->all() as $message) {
print_r($message);
}
exit;
}
示例13: extendUpdate
/**
* Extend update validations.
*
* @param \Illuminate\Contracts\Validation\Validator $validator
*
* @return void
*/
protected function extendUpdate(ValidatorResolver $validator)
{
$name = Keyword::make($validator->getData()['name']);
$validator->after(function (ValidatorResolver $v) use($name) {
if ($this->isRoleNameGuest($name)) {
$v->errors()->add('name', trans('orchestra/control::response.roles.reserved-word'));
}
});
}
示例14: formatErrors
/**
* Format error messages for ajax requests
*
* @param Validator $validator
* @return array
* @internal param Request $request
*/
protected function formatErrors(Validator $validator)
{
$errors = $validator->errors()->all();
$error = '';
foreach ($errors as $errorMessage) {
$error = $errorMessage;
}
return ['success' => false, 'title' => trans('common.fail'), 'message' => $error];
}
示例15: formatValidationErrors
protected function formatValidationErrors(Validator $validator)
{
foreach ($validator->errors()->getMessages() as $key => $message) {
if (starts_with($key, 'roles')) {
$validator->errors()->add('roles', $message[0]);
}
}
return $validator->errors()->getMessages();
}