Update parent data when the child data is updated in Laravel

author
9
0 minutes, 25 seconds Read

Use the $touches property to update the parent timestamp when a child is updated.

Did you know you can update the parent model timestamp when a child is updated?

If you have a “belongsTo” or “belongsToMany” relationship you can define a “$touches” property to do this

class Comment extends Model
{
    protected $touches = ['post'];
    
    public function post()
    {
        return $this->belongs To (Post::class);
    }
}
PHP

We appreciate your support and are committed to providing you useful and informative content.
We are thankful for your ongoing support 
Share To:

Similar Posts

9 Comments

  1. avatar
    wwd.com says:

    Fantastic blog you have here but I was wanting to know if you knew of any
    discussion boards that cover the same topics talked about in this article?
    I’d really love to be a part of online community where I can get
    responses from other experienced individuals that share the same interest.
    If you have any suggestions, please let me know.
    Thanks a lot!

  2. avatar
    Alberto D. Harris says:

    Someone essentially help to make critically posts I’d state. That is the first time I frequented your website page and so far? I surprised with the research you made to create this actual publish incredible. Magnificent activity!

  3. avatar
    how long for shrooms says:

    I seriously love your site.. Great colors & theme. Did you make this site yourself?
    Please reply back as I’m planning to create my own personal blog and would love
    to know where you got this from or what the theme is named.
    Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *