/** * Initialize the form request with data from the given request. * * @param \Illuminate\Foundation\Http\FormRequest $form * @param \Symfony\Component\HttpFoundation\Request $current * @return void */ protected function initializeRequest(FormRequest $form, Request $current) { $files = $current->files->all(); $files = is_array($files) ? array_filter($files) : $files; $form->initialize($current->query->all(), $current->request->all(), $current->attributes->all(), $current->cookies->all(), $files, $current->server->all(), $current->getContent()); if ($session = $current->getSession()) { $form->setSession($session); } $form->setUserResolver($current->getUserResolver()); $form->setRouteResolver($current->getRouteResolver()); }
/** * failedValidation. * * @author Pedro Coutinho <*****@*****.**> * * @param \Illuminate\Contracts\Validation\Validator $validator * * @throws \Nodes\Validation\Exceptions\ValidationException * * @return void */ protected function failedValidation(Validator $validator) { if ($this->isApiRequest()) { throw new ValidationException($validator, $this->getErrorCodes()); } parent::failedValidation($validator); }
/** * Get the proper failed validation response for the request. * * @param array $errors * @return \Symfony\Component\HttpFoundation\Response */ public function response(array $errors) { if ($this->ajax() || $this->wantsJson()) { return response()->json(['messages' => $errors], 422); } return parent::response($errors); }
/** * {@inheritDoc} */ protected function failedAuthorization() { if (is_api_request()) { return app(Response::class)->unauthorizedError(); } return parent::failedAuthorization(); }
/** * Handle a failed authorization attempt. * * @return void */ protected function failedAuthorization() { if ($this->container['request'] instanceof Request) { throw new HttpException(403); } parent::failedAuthorization(); }
/** * @param \Illuminate\Contracts\Validation\Validator $validator * @return void * * @throws \Illuminate\Validation\ValidationException * @throws \Symfony\Component\HttpKernel\Exception\HttpException */ protected function failedValidation(Validator $validator) { if ($this->ajax() || $this->wantsJson()) { throw new ValidationException($validator); } parent::failedValidation($validator); }
protected function failedValidation(Validator $validator) { if (config('app.debug') || Request::is("api/*")) { throw new ValidationException($validator); } return parent::failedValidation($validator); }
/** * Get the validator instance for the request. * @return \Illuminate\Validation\Validator */ protected function getValidatorInstance() { $instance = parent::getValidatorInstance(); if (method_exists($this, 'prepareValidator')) { $this->prepareValidator($instance); } return $instance; }
protected function failedValidation(Validator $validator) { if ($this->ajax()) { $this->session()->flashInput($this->all()); $this->session()->flash('errors', $validator->getMessageBag()); } parent::failedValidation($validator); }
/** * {@inheritdoc} */ protected function formatErrors(Validator $validator) { if (is_null($this->errorsFormat)) { return parent::formatErrors($validator); } $errors = []; $messages = $validator->getMessageBag(); foreach ($messages->keys() as $key) { $errors[$key] = $messages->get($key, $this->errorsFormat); } return $errors; }
public function run($fields, RepositorieInterface $model, FormRequest $r) { $this->setModel($model); if (!is_array($fields)) { throw new BadMethodCallException("Argument fields in method UploadHelper::run must array"); } foreach ($fields as $field) { $files[$field] = $r->file($field); } if ($this->validate($files)) { foreach ($files as $field => $file) { if (!is_null($file)) { $name_file = $this->generateName($field, $file); $this->registerFile($field, $this->upload($file, $name_file)); } else { $this->registerFile($field, $this->generateName($field)); } } return true; } return false; }
public function __construct() { parent::__construct(); validator()->extend('unique_array', function ($attributes, $values) { $array = []; foreach ($values as $key => $value) { if (in_array($value, $array)) { return false; } $array[] = $value; } return true; }); }
public function getValidatorInstance() { $validator = parent::getValidatorInstance(); $validator->after(function () use($validator) { $input = $this->formatInput(); $checkcode = trim(strtoupper($input['checkcode'])); if ($checkcode[2] != '-' || strlen($checkcode) != 9) { $validator->errors()->add('checkcode', 'profile.invalide-code-format'); return $validator; } $localuser = UserProfile::findLocalUserByVerificationCode($input['checkcode']); if ($localuser == null) { $validator->errors()->add('checkcode', Lang::get("profile.invalid-code-value")); } }); return $validator; }
public function validate() { $this->beforeValidateCallback(); parent::validate(); $this->afterValidateCallback(); }
/** * Handle a failed validation attempt. * * @param \Illuminate\Contracts\Validation\Validator $validator * @return void * * @throws \Illuminate\Validation\ValidationException */ protected function failedValidation(\Illuminate\Contracts\Validation\Validator $validator) { flash()->error('Validation failed.'); parent::failedValidation($validator); }
public function validate() { Session::flash('error_location', 'login'); parent::validate(); }
/** * Handle a failed validation attempt. * * @param \Illuminate\Contracts\Validation\Validator $validator. * @return mixed */ protected function failedValidation(Validator $validator) { // Set custom error attibute names $validator->setAttributeNames($this->labels); //TODO not working. According to dd($validator) the instance has the right attibute names but they are not used! return parent::failedValidation($validator); }
public function __construct() { $this->validator = app('validator'); $this->validateConvenioBb($this->validator); parent::__construct(); }
/** * @param array $errors * * @return mixed */ public function response(array $errors) { return parent::response($errors)->with('notice-error', trans('tinyissue.we_have_some_errors')); }
/** * Determine if the request is sending JSON. * Overridden to ensure that JSON API content is correctly considered JSON. * * @return bool */ public function isJson() { return parent::isJson() || $this->header('CONTENT_TYPE') === 'application/vnd.api+json'; }
/** * Get all of the input and files for the request. * Returns only validated fields if FormRequest is $strict. * * @return array */ public function all() { $allInput = parent::all(); if (!$this->strict) { return $allInput; } $rules = $this->rules(); $allowedKeys = array_keys($rules); $result = []; foreach ($allowedKeys as $key) { if (stripos(Arr::get($rules, $key), 'array')) { // array overrides more specific rules continue; } $value = Arr::get($allInput, $key); if ($value !== NULL) { Arr::set($result, $key, $value); } } return $result; }
/** * @param Menu $menu * @param \Illuminate\Foundation\Http\FormRequest $request * @return array */ private function addMenuId(Menu $menu, FormRequest $request) { return array_merge($request->all(), ['menu_id' => $menu->id]); }
/** * When validating, first, set any checkbox fields that may be missing from the request; * then, run hoursToMinutes on time inputs */ public function validate() { $this->setCheckboxes(); parent::validate(); $this->hoursToMinutes(); }
public function __construct() { parent::__construct(); $this->validateMac(); }
/** * Get the validator instance and execute the filter sanitation. * @return \Illuminate\Contracts\Validation\Validator */ protected function getValidatorInstance() { $this->sanitize(); return parent::getValidatorInstance(); }
/** * Update the Paenl using the input provided by a FormRequest * * @param \Illuminate\Foundation\Http\FormRequest $request * * @return void */ public function updateFromRequest(Request $request) { foreach ($request->only($this->options()->keys()->toArray()) as $key => $value) { $this->updateSetting($key, $value); } }
/** * Sanitize input before validating. * * @return void */ public function validate() { $this->sanitize(); parent::validate(); }
/** * Initialize the form request with data from the given request. * * @param \Illuminate\Foundation\Http\FormRequest $form * @param \Symfony\Component\HttpFoundation\Request $request * @return void */ protected function initializeRequest(FormRequest $form, Request $current) { $form->initialize($current->query->all(), $current->request->all(), $current->attributes->all(), $current->cookies->all(), $current->files->all(), $current->server->all(), $current->getContent()); }
/** * Call the autoRegister method to register the custom rules and trigger the parent validate method. */ public function validate() { $this->autoRegister(); parent::validate(); }
/** * Handle a failed validation attempt. * * @param $validator * * @return mixed */ protected function failedValidation(Validator $validator) { flash()->error(trans('validation.failedForm')); parent::failedValidation($validator); }