Return ajax validation request from Laravel 5?

Good day! Weak with JS and laravel is not very strong(

First, did this "validation", but it's bad form?
$extention = $request->file('file')->getClientOriginalExtension();


 if( $extention == 'jpg' or $extension == 'jpeg' or $extension == 'png' or $extension == 'rar' )
{
 $name = $request->file('file')->getClientOriginalName();
 $img = $name .".".$extention;
 if( $request->file('file')->move( base_path() . '/public/images/catalog/', $img ) )
{
 $status = true;
}
}
else{
 $status = false;
}
 return response()->json ([STATUS => $status ]);

Using this approach I get the response as JSON and infer the client needs the message. But I want to use the "right" validation. because he wrote so php artisan make:request RequestName there actually wrote
public function rules()
{
 return [
//
 'file' => 'required|mimes:jpg,png,mp4,webm',
];
 }

And here not clear to me how to return the validation result as JSON for further processing? Thank you!
July 12th 19 at 16:55
1 answer
July 12th 19 at 16:57
Hi! Try this option :)

// Rules can make a function in the model
$rules = [
 'file' => 'required|mimes:jpg,png,mp4,webm',
];

$validation = Validator::make($request->all(), $rules);
if( $validation->fails() ) {
 $errors = $validation->messages()->toJson();
}

return response()->json([ "errors" => $errors ]);

Find more questions by tags AJAXLaravel