I know i can get the errors in a view with @if ($errors->any())
or similars. But what if I want to get the validation errors in the Controller
to return it as JSON?
RegisterRequest.php
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class RegisterRequest extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'name' => 'required|string|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
'password_confirmation' => 'required|string|min:6|same:password',
];
}
}
AuthController.php register function
public function register(RegisterRequest $request)
{
$request->errors();
}
Is there a wait to do something like that to get the validation error messages? I couldn't find anything in the documentation