企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[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'字段也更新了;