I have a checkbox element in my blade template and I want to know if it is possible to write an if statement inside of a html element.
This works:
@if($data->holiday)
<div class="input-field">
<input placeholder="" name="holiday" id="holiday" checked
type="checkbox"
value="1">
<label for="holiday">Holiday</label>
</div>
@else
<div class="input-field">
<input placeholder="" name="holiday" id="holiday"
type="checkbox"
value="1">
<label for="holiday">Holiday</label>
</div>
@endif
Due to the doublecode I want to write something like this:
<div class="input-field">
<input placeholder="" name="holiday" id="holiday"
//or
@if($data->holiday)?'checked':''@endif
type="checkbox"
value="1">
<label for="holiday">Holiday</label>
</div>
But inside the input tag the code generates a bunch of errors. Is there something special to know or do I have to do it like in my first example?
via Gabbax0r