I have a problem involving avatar
upload field: I don’t want that fiel be required, i don’t want update the pictures of avatar, how do I solve this?
edit.php
<form method="POST" action="<?= site_url('customer/update/'.$customer['id']) ?>" enctype="multipart/form-data">
<?= csrf_field() ?>
<input type="hidden" name="_method" value="PATCH">
<div class="form-group">
<label for="avatar">Avatar:</label>
<input class="form-control <?= isset($errors['avatar']) ? 'is-invalid' : '' ?>" name="avatar[]" type="file" multiple />
<?php echo session()->getFlashdata('errors')["avatar"] ?? "";?>
</div>
<br>
<button type="submit" class="btn btn-primary"><i class="fa fa-arrows-rotate"></i> Update</button>
</form>
PeopleController.php
public function update($id)
{
$model = new CostumerModel();
$validations = new CustomerValidation();
if (!$this->validate($validacoes->customer_update)) {
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
}
$processed_data = [
'customer_name' => trim($this->request->getVar('customer_name')),
];
$model->update($id, $processed_data);
if ($this->request->getFileMultiple('avatar')) {
$avatar_model = new AvatarModel();
$avatar_model->where('customer_id', $id)->delete();
foreach ($this->request->getFileMultiple('avatar') as $avatar) {
$original_name = $avatar->getName();
$image_path = 'uploads/avatars/' . $id . '/' . $original_name;
$avatar->move(WRITEPATH . 'uploads/avatars/' . $id, $original_name);
$avatar_model->insert([
'customer_id' => $id,
'image' => $image_path,
]);
}
}
return redirect()->to(route_to('indexPerson'));
}
CustomerValidation.php
public array $customer_update = [
'avatar' => 'permit_empty',
];
How do I solve this problem of obligatoriness of avatar
field.