Home » Php » Fill radio button with data coming from database Laravel Blade

Fill radio button with data coming from database Laravel Blade

Posted by: admin November 30, 2017 Leave a comment

Questions:

So I am now working with the update part of my program, now i want to populate my forms with the older records from my database to edit it. Now my problem is the radio button, how can select the true one. I tried this code, i use if on my radio buttons

    {{ Form::label('Type','Type')}}    
    {{ Form::radio('ctype', '1',if(($item->bname)==1){true}) }}
    {{ Form::label('Rooster','Rooster')}}    
    {{ Form::radio('ctype', '0') }}
    {{ Form::label('Hen','Hen')}}    

But I just get error 500, please help

Answers:

In the documentation it says:

echo Form::radio('name', 'value', true);

So you should go this way:

{{ Form::radio('ctype', '1', $item->bname == 1) }}

You shouldn’t need any additional brackets. Third param is a simple boolean value.