padamghimire75@gmail.com's avatar

"Why are the HTML input attributes not applying correctly in spatie/laravel-html?"

  {{-- Email Field --}}
    <div class="form-group col-12">
        {!! Html::label('email', __('core::form.users.email') . '(*)') !!}
        <div class="input-group mb-3">
            {!! Html::input('email', 'email', null, [
                'class' => 'form-control' . ($errors->has('email') ? ' is-invalid' : ''),
                'placeholder' => '[email protected]',
                'disabled' => $model->exists
            ]) !!}
            @include('core::admin.layouts.components.validation', ['name' => 'email'])
        </div>
    </div>

Why is the fourth parameter array, specifically the attributes like 'class' => 'form-control' . ($errors->has('email') ? ' is-invalid' : ''), 'placeholder' => '[email protected]', and 'disabled' => $model->exists, not working as expected when passed to Html::input() in this Laravel code?

Actual output is

<input type="email" name="email" id="email">
0 likes
3 replies
tykus's avatar

What is this package; and why is it considered preferable to raw HTML?

{!! Html::input('email', 'email', null, [
    'class' => 'form-control' . ($errors->has('email') ? ' is-invalid' : ''),
    'placeholder' => '[email protected]',
    'disabled' => $model->exists
]) !!}

vs.

<input type="email" 
       name="email" 
       id="email"
       class="form-control {{ $errors->has('email') ? 'is-invalid' : '' }}"
       placeholder="[email protected]" 
       {{ $model->exists ? 'disabled' : '' }}
>
Tray2's avatar

@padamghimire75@gmail.com I agree with @tykus, why not just write the html yourself, it's not that complicated, and if you make components of it, it's even easier.

Please or to participate in this conversation.