Ad

Creating A Form Label Element

- 1 answer

How to create form label element in laravel.

I want to convert below html

<label class="control-label">Status <span class="required">*</span></label>

I used

{!! Form::label('status', 'Status <span class="required">*</span>', array('class' => 'control-label')) !!}

But the output is

Status <span class="required">*</span>

The question is how to render HTML in it, Or is there a way?

Ad

Answer

You can't - Laravel Collective's Form::label function runs it through htmlspecialchars.

That said, Form::label is just generating HTML. You're fine using raw HTML for this - just add a for="status" to link it up to its form field.

<label class="control-label" for="status">Status <span class="required">*</span></label>

You could, I suppose, run the generated label through htmlspecialchars_decode, but I think that's uglier and confusing for someone else reading your code.

{!! htmlspecialchars_decode(Form::label('status', 'Status <span class="required">*</span>', array('class' => 'control-label'))) !!}
Ad
source: stackoverflow.com
Ad