Answer the question
In order to leave comments, you need to log in
Why doesn't Validator $errors work in Laravel 5.2?
Hello.
Faced such a problem. The validator is not working. It simply does not display anything, redirects back and that's it. What could be the problem?
user.php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable{
protected $fillable = [
'name', 'email', 'password',
];
protected $hidden = [
'password', 'remember_token',
];
public static $login_validation_rules = [
'email' => 'required|email|exists:users',
'password' => 'required'
];
}
public function handleLogin(Request $request){
$this->validate($request, User::$login_validation_rules);
$data = $request->only('email', 'password');
if(\Auth::attempt($data)){
return redirect()->intended('home');
}
return back()->withInput()->withErrors(['Email' => 'Email или пароль не верны']);
}
@if(count($errors))
<div class="alert alert-error">
<ul>
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
Answer the question
In order to leave comments, you need to log in
Why write these rules in the model
If you don’t want to write them in the controller, then you need to write them in the Form Requests
form-request-validation
The laravel standard authorization already has a validation method in the AuthController, as I understand it, you don’t use it
I'm writing a bike because I don't fully understand how Laravel works.
Answer to
kernel.php question
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Session\Middleware\StartSession::class,
];
Why write these rules in the model
If you don’t want to write them in the controller, then you need to write them in Form Requests
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question