Reputation: 11
My project is on storing reviews on products. I am using Laravel framework here. The review has a field for rating the product. I am using the jquery 'starrr' plugin for the rating.
Form :
{!! Form::open(['url'=>'/admin/reviews', 'role' => 'form', 'class' => 'form-horizontal']) !!}
<div class="form-group">
{!! Form::label('title', "Title:", ['class'=>'control-label col-md-2']) !!}
<div class="col-md-8">
{!! Form::text('title', null, ['class'=>'form-control'])!!}
</div>
</div>
<div class="form-group">
{!! Form::label('product_id', "Product:", ['class'=>'control-label col-md-2']) !!}
<div class="col-md-8">
{!! Form::select('product_id', $products, null, ['class'=>'form-control product_list'])!!}
</div>
</div>
<div class="form-group">
{!! Form::label('rating', "Rating:", ['class'=>'control-label col-md-2']) !!}
<div class="starrr"></div>
{!! Form::hidden('rating', null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
<div class="col-md-3 col-md-offset-4">
{!! Form::button('<i class = "fa fa-plus-circle"></i> Add New Review', ['type' => 'submit', 'class'=>'btn btn-primary btn-lg']) !!}
</div>
</div>
{!! Form::close() !!}
controller store method:
public function store(Request $request){
$rules = [
'product_id' => 'required',
'title' => 'required',
'content' => 'required',
];
$this->validate($request, $rules);
create($request->all());
return redirect('admin/reviews')->withSuccess('Review is created');
}
My question is how to get the rating value from the star rating, into the request object to store on the database? Thanks for your help in advance
Upvotes: 1
Views: 914
Reputation: 25221
$('.starrr').starrr({
change: function(e, value){
$('input[name="value"]').val(value)
}
})
This will set the input to the value of the starrr
plugin whenever it is changed. Then the input value will be sent to the server
Upvotes: 1