1/*
2When a model has a BelongsTo or BelongsToMany relationship with another model,
3Let us say Comment that belongs to a Blog, it could in some cases be helpful
4to update the parent’s timestamp when the child is updated.
5This can be done by adding the relationship to the $touches attribute.
6*/
7
8class Comment extends Model
9{
10 protected $touches = ['blog'];
11
12 public function blog()
13 {
14 return $this->belongsTo(App\Blog::class);
15 }
16}
17
18/*
19In Case we only want to Update One Model without needing change in other Model
20ie Update updated_at without updating other fields
21See the code here:
22*/
23public function updateUpdatedAt(){
24 $user = User::find(1);
25 $user->touch();
26}