Answer the question
In order to leave comments, you need to log in
Why is laravel validator not returning a message?
Hello.
Why might the validator not show the message?
When you enter invalid data, they do not pass, but there is no standard message.
AuthController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
class AuthController extends Controller
{
public function login(Request $request)
{
$this->validate($request, [
'email' => 'required|email',
'password' => 'required'
]); // Если данные не валидны то должно выдать стандартное сообщение, но ничего не происходит
return response()->json([
'token' => $token
], 200);
}
}
Route::post('/login', '[email protected]');
Answer the question
In order to leave comments, you need to log in
So try:
$validator = Validator::make($request->all(), [
'email' => 'required|email',
'password' => 'required'
]);
if ($validator->fails()) {
$errors = $validator->errors()->all();
return response()->json([
'error' => current($errors),
]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question