laravel学习教程之关联模型(7)

<?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有所帮助。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/5ca46c020df88a8c2b8e1156d1574bf3.html