I want to ask Bro, how to make a product review by the user who has bought the goods, I've tried to make, but not successful, the result is like this:
first, if the user (buyer) buy the goods and do the review is successful, but the form for the review is still there ... how do I remove the form for the user (buyer) who has done a review for the goods?
can do a review, when the product has not been reviewed #View Image
the form still exists despite having reviewed the goods #View Image
secondly, it is already purchased and reviewed by other users, the user (buyer with different account) make a purchase and succeed, but if make a review of the same item, can not the form does not appear, but already made a purchase ..
there is no form for the user, even after making a purchase #View Image
essentially like this if the goods have not been reviewed, can do the review and the form is still there even though it has done a review. but if you already have a review, other users (buyers) can not review the item (the form does not appear). well that's the problem where is Bro ?, in conditioning _ (if) _? or anything else?
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></h4>
<p></p>
<h3></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></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();
}
Products(Model).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');
}
}
thanks a lot for the answer :)
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire