0

I want to have a string as html with blade. I am not sure how to do this with blade using laravel. I have the following code:

<option value="New York" "{{{ Input::old('state', $user->state == 'New York' ?  'selected' : '') }}}">

The output of this is

 <option value="New York" "selected">New York</option>

and I want it to be this

<option value="New York" selected>New York</option>

How can I do this? Pointing me to resources would also help. Thank you.

1
  • what happens when you remove the quotes around the function? Commented Nov 23, 2014 at 5:24

1 Answer 1

2
<option value="New York" {{{ Input::old('state', $user->state) == 'New York' ?  'selected' : '' }}}>

Simply remove the quotes. Also it looks like you have a parenthesis in the wrong place. I fixed that as well.

And just an FYI for you, you can use Laravel's Form class to generate a select for you and automatically select the right option for you:

{{{ Form::select('state', $statesArray, Input::old('state', $user->state)) }}}
Sign up to request clarification or add additional context in comments.

3 Comments

When I remove the quotes I get an error "Use of undefined constant selected - assumed 'selected' " . I will try the form generator and if that works I will accept your answer.
you are removing the wrong quote. look at the answer carefully.
@itachi is correct. Make sure you don't remove the quotes around 'selected' as it is a string. Rather, remove the quotes around the blade {{{ }}} syntax which results in selected being unquoted in the HTML, which is what you desire.

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.