Touch parent updated_at in Laravel

It will help you to update the updated_at column data of the parent table while updating the data of the child table. Like we make a comment on a specific post and we want to update the updated_at column of the related (post) records of the posts table then it will help you to do so

Answers 1
  • Add touch property to child model to update the parent relationship to renew

    --PATH app\Models\Comment.php
    class Comment extends Model
    {
        protected $touches = ['post'];
    }
    
    0

    It will update the updated_at column of the related record of the posts table if you make a comment on this particular post.

  • Back to code snippet queries related laravel