📜  一对多 laravel - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:29.625000             🧑  作者: Mango

代码示例3
Suppose you have a Post model with a hasMany relationship with Comment. You may insert a Comment object related to a post by doing the following:

$post = Post::find(1);
$commentToAdd = new Comment(['message' => 'This is a comment.']);
$post->comments()->save($commentToAdd);