Edited data without changing photo

I edited data without changing the photo, can you help me?

And the code behind the update? are you trying this->validate() in update and $rules that validate the correct file for image?

yes , i use

my update


Model Data


Rules

Hey, @jeroapriyansah

use if statement before updating the model

if (is_null($this->photo)) {
  $this->photo = $model->photo;
}

$this->model->update(...);

can not bro , do you have example for me ?

As I can understand, when you call the modelData() you don’t assign any value to the properties at least you edit them in inputs. I think, you must assign values to your properties once select the editable entity or model like:

public function getModel()
{
   $model = PengurusModel::find($someId);
   this->nama = $model->nama;
   //.....fill all the related properties
}

Particularly I, when updates, check for changes in the properties and just the modified will be updated and for that I use another vars like:

public function getModel()
{
   $model = PengurusModel::find($someId);
   this->prevNama = $model->nama;
   //.....fill all the related properties
}

and in the update()

{
    $data = [];
    $validateData = [];
    if($this->nama !== $this->prevNama) {
          $data = array_merge($data, ['nama' => $this->nama]);
          $validateData = array_merge(['nama' => 'required']); 
   }
   //....check the other properties for changes
   $validation = Validator::make($data, $validateData)->validate();
   if(count($validation)) {
        PengurusModel::find($this->modelId)->update($validation);
   }
}

Hope this can help you a little

thanks you very much ,