When I edit a model having an image, I don't care about the image, unless the image is replaced by another one.
How to validate image path in editing form? Livewire 3
When I am creating recipe I have image from user
While creating I have this validation logic for image:
#[Validate]
#[Rule(['nullable','mimes:jpeg,png,webp'])]
public $image;
(its a file, so it works well)
But when I wanna to edit recipe image I have a problem, because in this case I am getting image like a string (path to that image) recipes-images/default/default_photo.png
How can I validate image when it is a string path?
I managed to solve this problem, I've created a new variable public $current_image and like you said:
...I don't care about the image, unless the image is replaced by another one.
So I can show to user $current_image and continue work without extra validation rules
<!-- current photo -->
@if($recipeForm->id)
<label>Current image</label>
<div class="mt-2">
<img src="{{ asset('storage/'. $recipeForm->current_image) }}">
</div>
@endif
Please or to participate in this conversation.