I had a strange problem regarding validation in Laravel 5.2. I reviewed the following questions about StackOverflow, but none of them seem to apply to my case:
Laravel validation not showing errors
Laravel validation does not return an error
The thing is, I'm trying to check a field titlebefore moving an object Cardto the database. When I submit the form with an empty field title, as expected, it will not pass validation. However, the array is $errorsnot populated when the mentioned validations fail. Can someone explain where I am wrong in this code?
public function create(Request $request)
{
$this->validate($request, [
'title' => 'required|min:10'
]);
Card::create($request->all());
return back();
}
@if(count($errors))
<ul>
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
@endif
<form method="POST" action="/cards">
{{ csrf_field() }}
<div class="form-group">
// The textarea does not get populated with the 'old' value as well
<textarea class="form-control" name="title">{{ old('title') }}</textarea>
</div>
<div class="form-group">
<button class="btn btn-primary" type="submit">Add Card</button>
</div>
</form>