2016-09-14 3 views
1

私のプロジェクトでは、製品に関するレビューを保存しています。私はここでLaravelフレームワークを使用しています。レビューには、製品を評価するためのフィールドがあります。私は評価のためにjquery 'starrr'プラグインを使用しています。laravelフォームテキスト入力で星ランク付けプラグインを使用する方法

フォーム:

{!! 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() !!} 

コントローラストア方法:

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'); 
} 

私の質問は、データベースに格納するリクエストオブジェクトに、星評価から評価値を取得する方法ですか?それが変更されるたびに、事前にあなたの助けのための おかげ

答えて

1
$('.starrr').starrr({ 
    change: function(e, value){ 
    $('input[name="value"]').val(value) 
    } 
}) 

これはstarrrプラグインの値に入力を設定します。その後、入力値はサーバに送信されます

+0

Jeffに感謝します。あなたの提案を試しましたが、成功しませんでした。 rev_ratingは名前フィールドです。 $( 'input [rev_rating = "value"]').val(value)はデフォルト値の3を返し続けます。 –

関連する問題