Skip to content

Instantly share code, notes, and snippets.

@asaokamei
Created April 21, 2014 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asaokamei/11130287 to your computer and use it in GitHub Desktop.
Save asaokamei/11130287 to your computer and use it in GitHub Desktop.
Eloquentでリレーションを作成する方法 ref: http://qiita.com/asaokamei/items/ce87090c155d7b4d7f6d
class Post extends Eloquent {
public comments() {
return $this->hasMany('Comment');
}
}
class Comment extends Eloquent {
public posts() {
return $this->BelongsTo('Post');
}
}
$comment->posts()->associate($post);
$post = $comment->post;
$post->comments()->save($comment);
$post->comments()->saveMany($comments);
$comments = $post->comments;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment