I want to ask sir :)
my case:
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 #View Image
when the user has done a review, the form is still there #View Image
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 #View Image
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></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 :)
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2jTe2Hx
via IFTTT
Aucun commentaire:
Enregistrer un commentaire