2

Does somebody know how to correcly create an input button using Laravel Blade? I needs to alternate between a active and inactive stated. That's why I'm using an if-statement.

This is my code for creating a input button inside a tabledata <td>.

@if ({{ $customer->active }})

        <input type="button" name="active" value="Active">

@else   

        <input type="button" name="active" value="Inactive">

@endif

Error

Parse error: syntax error, unexpected '<' (View:...)

Result (After implementing solution)

<td>
        <input type="button" id="active" name="active" 
        value="{{ $customer->active ? 'Active' : 'Inactive' }}">

</td>

enter image description here

2 Answers 2

6

If I understand you correctly you just want to toggle the value of the button right? Why not just <input type="button" name="active" value="{{ $customer->active ? 'Active' : 'Inactive' }}">

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

Comments

1

If active is false, it wont print 0, thus you'll get this error.

{{ ($customer->active ? '1' : '0') }}

should work I think

3 Comments

Thank you for your reply, I don't think you need an echo. Blade renders it correcly.
Can you, for my learning and knowledge, test if my updated answer works? furthermore, shigg answer is better :)
hank you for the feedback! shigg's answer is what I would suggest you to use however :)

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.