/**
  * Push an error into the session.
  *
  * @param  string $field
  * @param  string $message
  * @return $this
  */
 protected function withError($field, $message)
 {
     $errors = new ViewErrorBag();
     $errors->put('default', new MessageBag([$field => [$message]]));
     $this->session(['errors' => $errors]);
     return $this;
 }
Пример #2
0
 /**
  * Reads the first Message from ViewErrorBag if existent
  * @param  ViewErrorBag $errors
  * @param  string     $key
  * @return bool|string
  */
 private function getFirstErrorMessage(ViewErrorBag $errors, $key)
 {
     if ($errors->has($key)) {
         return $errors->first($key);
     }
     return false;
 }
 public function testErrorDisplay()
 {
     $viewErrorBag = new ViewErrorBag();
     $viewErrorBag->put('default', new MessageBag(['test' => ['Generic error message']]));
     $formBuilder = new FoundationFiveFormBuilder($this->htmlBuilder, $this->urlGenerator, 'abc', $viewErrorBag);
     $input = $formBuilder->wrappedText('test', 'Test:');
     $this->assertEquals('<label class="error">Test:<input class="error error" name="test" type="text"></label><small class="error">Generic error message</small>', $input);
 }
Пример #4
0
 /**
  * Adds to or creates a ViewErrorBag & flashes the error for handling in the
  * layout (or wherever). Can be called from any controller method.
  * @param string $msg
  */
 public static function addErrorMsg($msg)
 {
     if (!static::$errorMsgBag instanceof MessageBag) {
         static::$errorMsgBag = new MessageBag();
     }
     static::$errorMsgBag->add('error', $msg);
     //session()->forget('errorBag');
     //session(['errorBag'=>static::$errorMsgBag]);
     $viewErrorBag = session('errors');
     if (!$viewErrorBag instanceof ViewErrorBag) {
         $viewErrorBag = new ViewErrorBag();
         session()->flash('errors', static::$viewErrorBag);
     }
     $viewErrorBag->put('PkControllerErrors', static::$errorMsgBag);
     session()->flash('errors', static::$errorMsgBag);
 }
Пример #5
0
 /**
  * @param $name
  * @return array
  */
 protected function getErrorClass($name)
 {
     $class = [];
     if ($this->errors->has($name)) {
         $class[] = 'has-error';
     }
     return $class;
 }
Пример #6
0
 /**
  * @param string $name
  * @param string $locale
  *
  * @return string
  */
 public function error($name, $locale = null)
 {
     return $this->html()->error($this->errors->first($name));
 }
Пример #7
0
 /**
  * @param \Illuminate\Support\MessageBag|\Illuminate\Support\ViewErrorBag $errors
  * @return $this
  */
 public function errors($errors)
 {
     if ($errors instanceof \Illuminate\Support\ViewErrorBag) {
         $this->errors = $errors->getBag($this->formName);
     } else {
         $this->errors = $errors;
     }
     return $this;
 }
Пример #8
0
 public function error(string $name) : string
 {
     return Html::error($this->errors->first($name));
 }
Пример #9
0
 /**
  * Returns errors for the field
  *
  * @param ViewErrorBag $errors
  * @param string $name
  * @return string
  */
 public function fieldErrors(ViewErrorBag $errors, $name)
 {
     $html = '<ul class="form-group__errors">';
     foreach ($errors->get($name) as $error) {
         $html .= '<li>' . $error . '</li>';
     }
     return $html .= '</ul>';
 }
Пример #10
0
 public function getPersonalInformation()
 {
     $borrower = \Auth::user()->getBorrower();
     $personalInformation = $borrower->getPersonalInformation();
     $form = new PersonalInformationForm($borrower);
     $form->handleData($form->getDefaultData());
     $errors = new ViewErrorBag();
     $errors->put('default', $form->getMessageBag());
     Session::flash('errors', $errors);
     $isFacebookRequired = $this->borrowerService->isFacebookRequired($borrower);
     $facebookJoinUrl = $this->facebookService->getLoginUrl('borrower:facebook-verification', ['scope' => 'email,user_location,publish_stream,read_stream']);
     if ($isFacebookRequired) {
         \Flash::error('Facebook verification required.');
     }
     return \View::make('borrower.personal-information', ['personalInformation' => $personalInformation, 'form' => $form, 'facebookJoinUrl' => $facebookJoinUrl, 'borrower' => $borrower, 'isFacebookRequired' => $isFacebookRequired]);
 }