How to create a radio button field in Laravel

Use the following code to create a radio button field in Laravel. First parameter is the name of the field and second parameter is the value of that field.

Useful Read : How to Install Illuminate/HTML Package In Laravel 5

{{ Form::radio('name', 'value') }}

This will generate,

<input name="name" type="radio" value="value">

You can also pass a third argument as true for generating a pre-checked radio button.

{{ Form::radio('name', 'value', true); }}

The above code will generate following HTML output,

<input checked="checked" name="name" type="radio" value="value">

To add HTML attributes to the radio button field pass a fourth argument as an associative array.

{{ Form::radio('name', 'value', null, ['class' => 'myClass']) }}

This will add a class attribute to Radio button field.

<input class="myClass" name="name" type="radio" value="value">

 

0 Comments

Leave a Comment.