reza kia
reza kia

Reputation: 163

how to save radio buttons value in mysql from laravel

i have below code in my laravel blade:

<div class="stars">
    <input class="star star-5" id="star-5" type="radio" name="star"/>
    <label class="star star-5" for="star-5"></label>
    <input class="star star-4" id="star-4" type="radio" name="star"/>
    <label class="star star-4" for="star-4"></label>
    <input class="star star-3" id="star-3" type="radio" name="star"/>
    <label class="star star-3" for="star-3"></label>
    <input class="star star-2" id="star-2" type="radio" name="star"/>
    <label class="star star-2" for="star-2"></label>
    <input class="star star-1" id="star-1" type="radio" name="star"/>
    <label class="star star-1" for="star-1"></label>
</div>

when i use dd($request->all()) it returned these line:

array:4 [▼
    "inputstar" => "11"
    "star" => "on"
    "products_id" => "84"
    "products_review" => "aaaaaa"
]

this code is for getting star rate

now , how to save radio buttons value in mysql from laravel code?

Upvotes: 1

Views: 2189

Answers (2)

Amirsadjad
Amirsadjad

Reputation: 515

You are getting "on" because you haven't specified a value for your inputs. just add a value to each of your input fields and the form will return the given value for each input.

Upvotes: 4

Imran
Imran

Reputation: 4750

You can change your form as below:

<div class="stars">
@for($i = 5; $i >= 1; $i--)
  <input class="star star-{{$i}}" id="star-{{$i}}" type="radio" name="star" value="{{$i}}"/>
  <label class="star star-{{$i}}" for="star-{{$i}}"></label>
@endfor
</div>

Now, if you dd($request->all()); it should give you the value of star instead of the text on.

Upvotes: 2

Related Questions