合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
[TOC] 跨模型更新时间戳 简单的来说,就是一条评论更新的时候,顺便把文章的'updated_at'字段也更新了; ~~~ namespace App; use Illuminate\Database\Eloquent\Model; class Comment extends Model { /** * All of the relationships to be touched. * * @var array */ protected $touches = ['post']; /** * Get the post that the comment belongs to. */ public function post() { return $this->belongsTo('App\Post'); } } ~~~ 设置$touches这个属性; # 跨模型更新时间戳 简单的来说,就是一条评论更新的时候,顺便把文章的'updated_at'字段也更新了; ~~~ namespace App; use Illuminate\Database\Eloquent\Model; class Comment extends Model { /** * All of the relationships to be touched. * * @var array */ protected $touches = ['post']; /** * Get the post that the comment belongs to. */ public function post() { return $this->belongsTo('App\Post'); } } ~~~ 设置$touches这个属性; 然后你更新Comment的时候,就会把Post的'updated_at'字段也更新了;