Touch parent updated_at in Laravel

Updated at 13-Jan-2022, By samar

Touch parent updated_at in Laravel

With this article, we’ll look at some examples of how to address the "Touch parent updated_at in Laravel" problem.

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
  • 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'];
    }
    

    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