Touch parent updated_at in Laravel

Created 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

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.