我想检索页面中 post_id(post1) 下的所有评论:
//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
模型注释.php
public function post()
{
return $This->belongsTo('Post');
}
模型post.php
public function comments()
{
return $this->hasMany('Comment');
}
控制器postController.php
public function show($id)
{
$comments = Post::where('post_id','=',$id)->first()
->comments()->where('post_id','=',$id)->get();
}
当我访问 //localhost/posts/post1/ 时,没有显示相关评论。SQL运行如下:
select * from `posts` where `post_id` = 'post1' limit 1
select * from `comments` where `comments`.`post_id` = '1' and `post_id` = 'post1'
如何删除`post_id
= '1'` 以检索相应的评论?