0

I am populating a radio button by using form::model in laravel. The populate form is in blade php. Why is the radio button not populating automatically like the textarea, textbox and drop down list?

{{ Form::model($teacher, array('route'=> array('updateteacher', $teacher->id))) }}
{{ Form::label('gender', 'Enetr your gender') }}
{{ Form::label('male', 'Male') }}
{{ Form::radio('gender', 'male') }} 
{{ Form::label('famle', 'Female') }}
{{ Form::radio('gender', 'female', $teacher->gender==1) }}
{{ Form::close() }}

I'm working in laravel 4.2, the table name is teacher and column name is gender.

2
  • 2
    When using Form::model, be sure to close your form with Form::close. Is there an error or something? Can you give some more information about what is going wrong? Commented Aug 11, 2015 at 15:30
  • Suggestion: use a question mark in your question to avoid attracting close votes. Commented Aug 11, 2015 at 16:42

2 Answers 2

2

I think the correct syntax is like ($teacher->gender == 'male') which is in your case:

{{ Form::model($teacher, array('route'=> array('updateteacher', $teacher->id))) }}
{{ Form::label('gender', 'Enter your gender') }}
{{ Form::label('male', 'Male') }}
{{ Form::radio('gender', 'male', ($teacher->gender == 'male')) }} 
{{ Form::label('female', 'Female') }}
{{ Form::radio('gender', 'female', ($teacher->gender == 'female')) }} 
{{ Form::close }}

And don't forget the Form::close.

Sign up to request clarification or add additional context in comments.

Comments

1

I am not sure with 4.2 but try

{{ Form::model($teacher, array('route'=> array('updateteacher', $teacher->id)))}}
{{ Form::label('gender','Enter your gender') }}
{{ Form::label('male','Male')}}
{{ Form::radio('gender' , 'male', $teacher->gender) }} 
{{ Form::label('female','Female') }}
{{ Form::radio('gender', 'female', $teacher->gender) }} 

If that doesn't work try this.

{{ Form::model($teacher, array('route'=> array('updateteacher', $teacher->id)))}}
{{ Form::label('gender','Enetr your gender') }}
{{ Form::label('male','Male')}}
{{ Form::radio('gender' , 'male', ($teacher->gender==true)?1:0) }} 
{{ Form::label('female','Female') }}
{{ Form::radio('gender', 'female', ($teacher->gender==true)?1:0) }} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.