laravel-validation

Validation error in Laravel - $errors array does not get populated after the validation failure

情到浓时终转凉″ 提交于 2019-11-26 23:31:15
问题 I've ran into a strange issue regarding validations in Laravel 5.2. I reviewed following questions on StackOverflow, but none of them seems to apply to my case: Laravel validation not showing errors Laravel Validation not returning error The thing is, that I am trying to validate a title field, before persisting the Card object into the database. When I submit the form with an empty title field, as expected, It doesn't pass the validations. However, the $errors array doesn't get populated

How to force FormRequest return json in Laravel 5.1?

梦想与她 提交于 2019-11-26 22:51:16
问题 I'm using FormRequest to validate from which is sent in an API call from my smartphone app. So, I want FormRequest alway return json when validation fail. I saw the following source code of Laravel framework, the default behaviour of FormRequest is return json if reqeust is Ajax or wantJson. //Illuminate\Foundation\Http\FormRequest class /** * Get the proper failed validation response for the request. * * @param array $errors * @return \Symfony\Component\HttpFoundation\Response */ public

ErrorBag is always empty in Laravel 5.2

元气小坏坏 提交于 2019-11-26 11:40:02
问题 I was creating a new Laravel project and when debugging the errors of a form request, I noticed that my ErrorBag was always empty. Even when in the controller $validator->fails() returned true . I tried every solution I found on the internet but nothing worked. Even when creating a fresh project with composer (as described here) my out of the box auth system has an empty error bag when leaving all the field empty. And yes, all the routes are using the middleware group web. Any ideas what is

Laravel 5.2 validation errors

一笑奈何 提交于 2019-11-26 11:09:40
问题 I have some trouble with validation in Laravel 5.2 When i try validate request in controller like this $this->validate($request, [ \'title\' => \'required\', \'content.*.rate\' => \'required\', ]); Validator catch error, but don\'t store them to session, so when i\'m try to call in template this code @if (isset($errors) && count($errors) > 0) <div class=\"alert alert-danger\"> <ul> @foreach ($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> </div> @endif Laravel throw the

Undefined variable: errors in Laravel

独自空忆成欢 提交于 2019-11-26 09:09:36
问题 When I want to register a user in my laravel project, the page always says Undefined variable: errors (View: /var/www/resources/views/auth/register.blade.php)\" According to the Laravel documentation, $errors should always automatically be set: So, it is important to note that an $errors variable will always be available in all of your views on every request, allowing you to conveniently assume the $errors variable is always defined and can be safely used. I have this on on every view when I