:Laravel 4 웅변 'hasMany의'보다는 기본 검색 값을 설정하는 방법 primay 키
이//localhost/posts/post1/
테이블
id:int[primary], comment:varchar, post_id:varchar, comment_id:varchar
1 this is a comment post_1 comment_1
을 코멘트를
테이블 게시물
id:int[primary], post_title:varchar, post_id:varchar
1 this is post title post_1
모델 comment.php
public function post()
{
return $This->belongsTo('Post');
}
모델 post.php
public function show($id)
{
$comments = Post::where('post_id','=',$id)->first()
->comments()->where('post_id','=',$id)->get();
}
내가 방문
public function comments()
{
return $this->hasMany('Comment');
}
컨트롤러 postsController.php
// localhost를/글/post1/어떤 관련 댓글이 표시되지 않습니다. 는 SQL은 다음과 실행 :select * from `posts` where `post_id` = 'post1' limit 1
select * from `comments` where `comments`.`post_id` = '1' and `post_id` = 'post1'
어떻게 대응 주석을 검색 할 수 1'` '`post_id
=을 제거 할 수 있습니까?
에 의해 개별 게시물을 얻을 수 있습니다. 실행 된 SQL은 어떻게 얻었습니까? –