mardi 25 juillet 2017

populate select in Laravel form with value from model

I made form with select. Here is code:

{!! Form::model($customerAccount, ['route' => ['admin.customerAccount.update', $customerAccount->id_customer_account], 'method' => 'PUT', 'class' => 'form-horizontal']) !!}

...

<div class="@if ($errors->has('cacct_active'))has-error has-feedback @endif form-group">
    {!! Form::label('cacct_active', 'Status: *',['class' => 'col-md-4 control-label']) !!}
        <div class="col-md-8">
             {!! Form::select('cacct_active',$customerAccount->getStatusList(),null,['class' => 'form-control', 'required' => 'required', 'autofocus' => 'none']) !!}
        </div>
</div>

I have options loaded by $customerAccount->getStatusList() and want default selected option to be value from my object. But it does not happen, selected is just the first one from options.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire