Ошибка проверки валидатора laravel, даже если я загружаю тип файла jpg png git и т. д., он говорит, пожалуйста, загрузите тип файла jpn png, загрузите изображение файла, пожалуйста, кто-нибудь, помогите мне, мой html-код:
public function saveCelebrity(Request $request)
{
$inputData = array_map('trim', $request->all());
$passwordRegex = '/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[!@#$%^&*])[A-Za-z\d!@#$%^&*]{10,}$/';
$mobileRegex = '/^\d{10}$/';
$customMessages = [
'name.regex' => 'The name field should contain only letters and spaces.',
'phone.regex' => 'Invalid mobile number format.',
'password.regex' => 'The password must have at least one uppercase letter, one lowercase letter, one number, one special character, and be at least 10 characters long.',
'facebook.required' => 'The Facebook profile link is required.',
'instagram.required' => 'The Instagram profile link is required.',
'youtube.required' => 'The Youtube profile link is required.',
'photo1.required' => 'Profile photo one is required.',
'photo2.required' => 'Profile photo two is required.',
'photo1.image' => 'The file must be an image.',
'photo2.image' => 'The file must be an image.',
'photo3.image' => 'The file must be an image.',
'photo4.image' => 'The file must be an image.',
'photo5.image' => 'The file must be an image.',
'photo6.image' => 'The file must be an image.',
];
if ($request->name) {
$validator = Validator::make($inputData, [
'name' => 'required|regex:/^[a-zA-Z\s]+$/',
'email' => 'required|email|unique:users',
'phone' => ['required', "regex:{$mobileRegex}"],
'role_id' => 'required',
'status' => 'required',
'account_status' => 'required',
'facebook' => 'required',
'instagram' => 'required',
'youtube' => 'required',
'photo1' => 'required|mimes:jpeg,png,jpg,gif|max:2048',
'photo2' => 'required|mimes:jpeg,png,jpg,gif|max:2048',
'photo3' => 'nullable|mimes:jpeg,png,jpg,gif|max:2048',
'photo4' => 'nullable|mimes:jpeg,png,jpg,gif|max:2048',
'photo5' => 'nullable|mimes:jpeg,png,jpg,gif|max:2048',
'photo6' => 'nullable|mimes:jpeg,png,jpg,gif|max:2048',
]);
} else {
$validator = Validator::make($inputData, [
// 'name' => 'required|regex:/^[a-zA-Z\s]+$/',
'email' => 'required|email|unique:users',
'phone' => ['required', "regex:{$mobileRegex}"],
'role_id' => 'required',
'status' => 'required',
'account_status' => 'required',
]);
}
// dd($inputData);
$validator->setCustomMessages($customMessages);
if ($validator->fails()) {
return redirect()->back()->withErrors($validator)->withInput($inputData);
}
$input = $request->all();
/*for User table data insertion */
$input['unique_number'] = 'meet-' . random_int(10000, 99999);
$input['username'] = trim(strtolower($inputData['name']) . random_int(100000, 999999));
$input['is_celebrity'] = 1; //Celebrity Account
$input['is_created_admin'] = 1; //Created by admin
$user = User::create($input);
/*for Profile table data insertion */
if($request->name) {
$socialLinks = [
[
"social_type" => "instagram",
"social_link" => $request->instagram,
],
[
"social_type" => "facebook",
"social_link" => $request->facebook,
],
[
"social_type" => "youtube",
"social_link" => $request->youtube,
],
];
$uploadedImages = [];
$images = [];
for ($i = 1; $i hasFile("photo$i")) {
$photoPath = Storage::disk('s3')->put('images', $request->file("photo$i"));
$photoUrl = Storage::disk('s3')->url($photoPath);
$uploadedImages["image$i"] = $photoUrl;
$images[] = ["images" => $photoUrl];
}
}
$profile = Profile::create([
'user_id' => $user->id,
'name' => $request->name,
'social_media_links' => json_encode($socialLinks),
'images' => json_encode($images),
]);
}
return redirect('admin/celebrities-list')->with('status', 'Celebrity has been created successfully.');
}
изображение ошибки:
пожалуйста, помогите мне, что я могу сделать, чтобы устранить эту ошибку и проверить, что загруженный файл является изображением в формате jpg, png, gif и т. д. Я все попробовал, но все равно не могу найти ошибку почему валидатор ведет себя вот так, почему возникает ошибка в загруженном файле изображения
Ошибка проверки валидатора laravel, даже если я загружаю тип файла jpg png git и т. д., он говорит, пожалуйста, загрузите тип файла jpn png, загрузите изображение файла, пожалуйста, кто-нибудь, помогите мне, мой html-код: [code] Profile photos
[/code] мой код контроллера[code]public function saveCelebrity(Request $request) { $inputData = array_map('trim', $request->all()); $passwordRegex = '/^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[!@#$%^&*])[A-Za-z\d!@#$%^&*]{10,}$/'; $mobileRegex = '/^\d{10}$/';
$customMessages = [ 'name.regex' => 'The name field should contain only letters and spaces.', 'phone.regex' => 'Invalid mobile number format.', 'password.regex' => 'The password must have at least one uppercase letter, one lowercase letter, one number, one special character, and be at least 10 characters long.', 'facebook.required' => 'The Facebook profile link is required.', 'instagram.required' => 'The Instagram profile link is required.', 'youtube.required' => 'The Youtube profile link is required.', 'photo1.required' => 'Profile photo one is required.', 'photo2.required' => 'Profile photo two is required.', 'photo1.image' => 'The file must be an image.', 'photo2.image' => 'The file must be an image.', 'photo3.image' => 'The file must be an image.', 'photo4.image' => 'The file must be an image.', 'photo5.image' => 'The file must be an image.', 'photo6.image' => 'The file must be an image.', ];
return redirect('admin/celebrities-list')->with('status', 'Celebrity has been created successfully.'); } [/code] изображение ошибки: [img]https://i.stack.imgur.com/LE8nE. png[/img]
пожалуйста, помогите мне, что я могу сделать, чтобы устранить эту ошибку и проверить, что загруженный файл является изображением в формате jpg, png, gif и т. д. Я все попробовал, но все равно не могу найти ошибку почему валидатор ведет себя вот так, почему возникает ошибка в загруженном файле изображения