By convention, $request->validate([]) will return the errors to the view. However you are assigning it to a variable ($validatedData) so laravel thinks that you are treating the data anyways.
Just remove the assigment of $validatedData and laravel will return it for you:
public function store(Request $request)
{
$request->validate([
'name' => 'required|max: 10',
'avatar' => 'required|image',
'slug' => 'required',
'description' => 'required',
]);
...
}
By convention, $request->validate([]) will return the errors to the view. However you are assigning it to a variable ($validatedData) so laravel thinks that you are treating the data anyways.
thanks but makes no difference, only refresh the view
try this
$this->validate($request, [ 'name' => 'required|max: 10', 'avatar' => 'required|image', 'slug' => 'required', 'description' => 'required', ]);
$this->validate($request, [ 'name' => 'required|max: 10', 'avatar' => 'required|image', 'slug' => 'required', 'description' => 'required', ]);
try this but return this error:
Symfony\Component\Debug\Exception\FatalThrowableError thrown with message "Argument 1 passed to LaraDex\Http\Controllers\Controller::validate() must be an instance of Illuminate\Http\Request, array given, called in /Users/jerefigueroa/.bitnami/stackman/machines/xampp/volumes/root/htdocs/laravel/cursoLaravel/app/Http/Controllers/TrainerController.php on line 63"
Please make sure that the form action is pertaining to the controller on which your store method is defined.
that's ok
can you please do {{ $errrors ? dd($errors) : null }}
And post here what you got
i got this
but this way:
@if ($errors->any())
{{ $errors ? dd($errors) : null }}
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $message)
<li>{{ $message }}</li>
@endforeach
</ul>
</div>
@endif
makes no difference, refresh the view
It's strange but solve the problem by changing local server. I used XAMPP and now I use MAMP and everything works perfect. If you are working locally with Laravel I recommend not using XAMPP.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community