🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[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'字段也更新了;