Answer the question
In order to leave comments, you need to log in
Return ajax validation from request Laravel 5?
Good afternoon! Weak with JS and not very strong with laravel (
At first I did such a "validation", but is it bad form?
$extention = $request->file('file')->getClientOriginalExtension();
if( $extention == 'jpg' or $extention == 'jpeg' or $extention == 'png' or $extention == '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 ]);
public function rules()
{
return [
//
'file' => 'required|mimes:jpg,png,mp4,webm',
];
}
Answer the question
In order to leave comments, you need to log in
Hey! Try this option :)
// Правила можешь вынести в функцию в модели
$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 ]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question