我想问问Bro,如何由购买商品的用户进行产品评审,我试图制作,但不成功,结果如下:
首先,如果用户(买方)购买商品并且审核成功,但审核表单仍然存在...如何删除已完成审核的用户(买方)的表单对于货物?
can do a review, when the product has not been reviewed #View Image
the form still exists despite having reviewed the goods #View Image
其次,它已被其他用户购买和审核,用户(具有不同帐户的买家)进行购买并成功,但如果对同一项目进行审核,则表格不会出现,但已经制作购买..
there is no form for the user, even after making a purchase #View Image
基本上就像这样 如果货物没有经过审查,可以进行审查,即使已经进行了审查,表格仍然存在。 但如果您已经有审核,则其他用户(买方)无法审核该项目(表单未显示)。 那么问题是Bro ?,在条件_(如果)_?或其他什么?
viewproduct.blade.php
<div role="tabpanel" class="tab-pane fade" id="profile">
<h2>Reviews</h2>
@foreach($reviews as $data)
<div class="panel panel-default">
<div class="panel-body">
<h4>{{ $data->user['name'] }}</h4>
<p>{{ $data->ulasan }}</p>
<h3>{{ $data->rating }}</h3>
</div>
</div>
@endforeach
@if(Auth::user() && Auth::user()->id == $show->order['user_id'])
@if($errors->any())
<div class="alert alert-warning">
<ul>
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
//form for review (I cut the code)
@endif
</div>
StoreController.php
public function ViewProduct($id)
{
$show = Products::findOrFail($id);
$related = Products::where('kategori_id', $show->kategori_id)
->orderByRaw('RAND()')
->take(10)
->get();
$reviews = Reviews::where('product_id', $show->id)->get();
return view('shop.viewproduct', compact('show','related','order','reviews'));
}
public function StoreReviewProduct(Request $request)
{
$this->validate($request, [
'rating' => 'required',
'description' => 'required|min:10',
]);
$addreview = new Reviews([
'product_id' => $request['product_id'],
'user_id' => Auth::user()->id,
'rating' => $request['rating'],
'description' => $request['description']
]);
$addreview->save();
Session::flash('success','thanks for adding review!');
return redirect()->back();
}
产品(模型).PHP
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Products extends Model
{
protected $fillable = ['kategori_id','nama_product','deskripsi','harga','pict','stok','review','id_kios'];
public function kios()
{
return $this->belongsTo(Kios::class,'id_kios');
}
public function order()
{
return $this->belongsTo(Orders::class,'id','product_id');
}
}
非常感谢答案:)
答案 0 :(得分:0)
你应该在is_buyed
表上创建另一个字段(boolean) 'product'
。
当某人(通常是第一个用户)购买该产品时 - &gt; 'is_buyed'
字段应更新为true。
在此之后,您可以查看Auth::user() && Auth::user()->id == $show->order['user_id'] && !$product->is_buyed
答案 1 :(得分:0)
看起来您已经设置了评论模型。
在Products模型中,您可以考虑创建一个函数,该函数返回当前用户是否已提交评论的布尔值。这将允许您在刀片文件中设置@if条件。
Task[] tasks = { task1, task2 };
ICommand command3 = new TestCommand3();
Task task3 = Task.Factory.ContinueWhenAll(tasks, (setOfTasks) =>
{
Console.WriteLine("Task3");
});
然后在你的刀片中:
public function reviews(){
return $this->belongsToMany(Reviews::class);
}
public function currentUserHasSubmittedReview(){
$countOfReviews = $this->reviews()
->where('user_id', Auth::user()->id)
->where('product_id', $this->id)
->get();
return ($countOfReviews > 1 ? true : false);
}
如果对如何运作有疑问,请与我们联系。