<?php 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'); } }
现在,当你更新 Comment 时,其所属的 Post 将会同时更新 updated_at 列:
$comment = App\Comment::find(1); $comment->text = 'Edit to this comment!'; $comment->save();
以上就是laravel学习教程之关联模型的全部内容,希望对大家学习php有所帮助。
您可能感兴趣的文章: