mysql> select * from review;
+----+----------+--------+------------+---------------------+---------------------+----------+------+---------+-----------+
| id | review | rating | product_id | created_at | updated_at | approved | spam | user_id | parent_id |
+----+----------+--------+------------+---------------------+---------------------+----------+------+---------+-----------+
| 1 | how much | 2 | 25 | 2017-05-05 12:02:02 | 2017-05-05 12:02:02 | 1 | 0 | 10 | NULL |
| 2 | 20 | NULL | 25 | 2017-05-05 12:02:35 | 2017-05-05 12:02:35 | 1 | 0 | 10 | 1 |
| 3 | ok | NULL | 31 | 2017-05-08 05:09:01 | 2017-05-08 05:09:01 | 1 | 0 | 9 | 2 |
| 4 | 30 | NULL | 31 | 2017-05-08 05:25:47 | 2017-05-08 05:25:47 | 1 | 0 | 9 | 3 |
| 5 | 40 | NULL | 31 | 2017-05-08 05:26:21 | 2017-05-08 05:26:21 | 1 | 0 | 9 | 4 |
| 6 | not fair | NULL | 31 | 2017-05-08 05:27:16 | 2017-05-08 05:27:16 | 1 | 0 | 9 | 5 |
| 7 | 80 | NULL | 31 | 2017-05-08 05:29:26 | 2017-05-08 05:29:26 | 1 | 0 | 9 | 1 |
| 8 | hi | NULL | 29 | 2017-05-08 05:37:25 | 2017-05-08 05:37:25 | 1 | 0 | 9 | NULL |
+----+----------+--------+------------+---------------------+---------------------+----------+------+---------+-----------+
的检查表,当我尝试。它正确地存储他们的父母的ID我想要添加注释的注释现在是显示在其父评论评论...
我怎样才能做到这一点?
在我的控制,我使用2个功能
函数来显示评论:
功能存储回顾:
public function review($id,Request $request){
$userid = Auth::user()->id;
$product = Product::find($id);
$product = Product::find($id);
$input = array(
'review' => Input::get('review'),
'rating' => Input::get('rating'),
'parent_id' => Input::get('parent_id')
);
$review = new Review;
$validator = Validator::make($input, $review->getCreateRules());
if ($validator->passes()) {
$review->storeReviewForProduct($id, $input['review'], $input['rating'],$input['parent_id']);
return redirect('product-detail/'.$id.'#reviews-anchor')->with('review_posted',true);
}
return Redirect::to('product-detail/'.$id.'#reviews-anchor')->withErrors($validator)->withInput();
}
这是我的看法:
@foreach($reviews as $val)
<div class="row">
<div class="col-md-12">
<p>{{$val['review']}} <span class="reply-comment">Reply</span></p>
{{-- Start Comment --}}
<div class="comment-box" style="display:none;">
<form action="{{ route('product.review',['id'=>$getProduct->id]) }}" method="post" id="comment">
{{csrf_field()}}
<input type="hidden" value="{{$val['id']}}" name="parent_id" id="parent_id">
<textarea class="form-control animated" cols="50" id="new-comment" name="review" placeholder="Leave your comment here" rows="5"></textarea>
<div class="text-right">
<button class="bc-btn-cancel-review" href="#" id="close-comment">Close</button>
<button class="bc-btn-save-review" type="submit" id="review">Comment</button>
</div>
</form>
</div>
{{-- End Comment --}}
</div>
</div>
@endforeach
我要像图像
向我们展示你的模型没有定义任何关系?你怎么传达你的观点。 –
你可以显示你迄今为止工作过的代码吗? –
编辑我的代码......可以请你检查一下 – Karthiga