mardi 17 novembre 2020

Laravel 8: Update model's timestamps without saving other attributes

I have an issue with the touch() method. Here's the flow:

  1. I'm temporarily decrypting the field inside the model to send to the authorized user.
  2. Updating updated_at timestamp with new log entry to indicate that field was decrypted.
  3. Returning decrypted model with the response without saving it in DB.

The issue:

So, here's the problem: When I do $model->touch() it is saving the whole model (as expected as Laravel's only checking if updated_at column isDirty(), not the whole model, and then calling $this->save()).

Question:

Is there another method that I can use to just update the model's timestamps regardless of if other attributes have been changed?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire