vendredi 1 avril 2016

Errors not displaying on View. Laravel-5

In my Laravel app I did some Validation of a form in a controller using the request variable. The validation seems to work, however when I try to display the errors in the view they are not showing up. I know the validation is working because as soon as I type something that is not a integer it brings me back to the view with the form. Here is the view with the form: (The 'if' statement that displays errorr is not working):

@if(count($errors) > 0)
  <ul>
      @foreach ($errors->all() as $error)
          <li>{{ $error }}</li>
      @endforeach
  </ul>
@endif
<form method='POST' action='/lorem/show'>



<label>Enter Number of Paragraphs</label>
<input type='hidden' name='_token' value='{{ csrf_token() }}'>
<input type='text'
        id='paragraph'
        name='paragraph'
        maxlength="2"
        size="5"
        <br/>

<input type="checkbox" name="header" value="header"/>Include Headers<br/><br/>
<button type="submit" class="btn btn-primary">
&nbsp;Create </button>
</form>

And here is the function in my controller:

public function postShow (Request $request) {

  $this->validate ($request, [
  'paragraph' => 'required|integer',
 ]);
}

Why are the errors not showing up in the view?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire