beforeDelete, softDelete and is_enabled field

The beforeDelete method is not working as it should within my plugin’s Model.
I have a table with some fields and when I delete a record I need to set the is_enabled field to false, but I can’t get it to work. It simply deletes the record (put the date in deleted_at) and the is_enabled fields remain the same.

Can you show a snippet of what you did?

     public function beforeDelete() {
         if ($this->is_enabled) {
             $this->is_enabled = False;
         }
     }

Bom dia!

Try this in your Model.php:

public function beforeDelete() {
        if ($this->is_enabled) {
            $this->is_enabled = false;
            $this->save();
        }
}
2 Likes

Thanks @apinard !!!

This worked for me really well!! :smiley: