getting last submit errors in PHP
Say I do something like this
$request->validate([
'title' => 'required|unique:posts|max:255',
'body' => 'required',
'publish_at' => 'nullable|date',
]);
The input doesn't validate, then a redirect back to the page with the form happens.
If I want to get the list of errors in PHP code how would I do that?
you can display all validation errors by looping errors
<!-- /resources/views/post/create.blade.php -->
<h1>Create Post</h1>
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<!-- Create Post Form -->
Codes are copied from laravel documentation - https://laravel.com/docs/10.x/validation#quick-displaying-the-validation-errors
@AungHtetPaing__ I saw how to get errors in a template. I would like to get the errors in PHP.
to maybe clarify my question:
- validator raises exception
- Laravel redirects to previous page
- I can get the form values in the PHP using old().
What is the specific code I can use in (any) PHP to get the errors from the validator
Please or to participate in this conversation.