Skip to content

Commit

Permalink
$touches attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
curder committed Nov 15, 2023
1 parent 33c13c4 commit faaebfd
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/partials/model-relations.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,22 @@ $users = Book::with('author:id,name')->get();
// Author -> belongsTo(Country::class)

$users = Book::with('author.country:id,name')->get();
```

## 更新父级

如果正在更新记录并想要更新 belongsTo 关系的 `updated_at` 列。

例如,添加新的帖子评论并希望 `posts.updated_at` 更新,只需要在 `Comment` 模型上定义 `$touches` 属性。

```php
class Comment extends Model
{
protected $touches = ['post'];

public function post()
{
return $this->belongsTo(Post::class);
}
}
```

0 comments on commit faaebfd

Please sign in to comment.