0

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

1
  • youre already validating it. Pls be a little more Specific with your Question Commented Nov 29, 2022 at 12:09

2 Answers 2

1

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,
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.