@tovamaulanairvan instead of hiding the form you can add a validation to check if the user has already reviewed the product.if they have it respond with a error "You have already reviewed on the product" and they they haven't the store function proceeds
How to Make a Review by Buyer For the Product?
I want to ask sir, I am beginner in laravel, I am making an online shop project with laravel but there is a problem here....
my problem :
first, the user (buyer) make the payment and successful, want to do a review (no record has been filled in tables reviews in the same product_id)
successful .. but the review form is still there, how to remove it for users who have done a review?
can do a review, when the product has not been reviewed

when the user has done a review, the form is still there

secondly, the user (another buyer with a different account) makes a purchase and payment (successful), wants to do a review ..
can not because there is a record that has been filled for the same product, how to solve this?
can not do a review for a product that already exists a review whereas a different user

Essentially, if the record review with the same empty product_id, can do a review but the form for the review is still available, but already do a review for the same goods, if the same product_id already, there can not do a review.
thank you :)
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();
}
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 :)
Please or to participate in this conversation.