For Examle I have Request Validation
'images.*' => 'mimes:jpg,jpeg|max:10240',
'images' => 'max:5',
It work In Create But , in update how I can check It , for example I already uploaded 4 image And In update I must add Only One Image , How I can validate it , is there any idea
CodePudding user response:
How about setting the validation value dynamically? Like, fetch the image record count first then set the value for the image validation.
//Fetch the remaining count
$remaining_image_count = 3;
$image_count_validation = 'max:' . $remaining_image_count;
//Setting the validation value
'images.*' => 'mimes:jpg,jpeg|max:10240',
'images' => $image_count_validation,
CodePudding user response:
if i understood your question right you want to check if theres maximum of 5 in the Database.
$count = 5 - Media::where('post_id', $post->id)->count();
$request->validate([
'title' => 'required|min:20',
'description' => 'required|min:50',
'img' => 'array|max:'.$count,
'img.*' => 'image|mimes:jpg,jpeg,png'
]);
if that was your question. Please be more Specific