php - How do I disable strict redirection when validation fails in Laravel 7?
Get the solution ↓↓↓In the case of a traditional HTTP request, a redirect response will be generated, while a JSON response will be sent for AJAX requests.
In Laravel 7, when validation fails, it automatically redirects user back to the previous page. Only when request is AJAX-like, Laravel generates JSON-error.
So my question is how to absolutely disable redirection when validation fails in Laravel 7 regardless request type?
Answer
Solution:
You need to do a manual validation, instead of using:
$request->validate()
you need to do it like this:
$validator = Validator::make($request->all(), [
'value1' => 'required|max:255',
'value2' => 'required',
]);
if ($validator->fails())
//Do whatever you want
}
//Continue normally if there are no validation errors
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: videoxxx
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.