I have a Laravel collection which returns different values. I want to fill the form always with the first set of the collection, so far there are data available.
Right now I am debugging and found an error. If there aren't data available I get Undefined offset: 0
. This is how I check if data are available and if yes it should fill out the form.
value="@php if($data){ echo $data[0]->client_id; } @endphp"
This is my full code:
<form class="tab-pane active" id="tab_1_1">
<div class="form-horizontal show" role="form" id="customer_details">
<div class="row">
<div class="col-md-6">
<h5>Kundendetails</h5>
<div class="form-group">
<label class="control-label col-sm-2" for="modal_cid">Kundennummer</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="modal_cid" value="@php if($data){ echo $data[0]->client_id; } @endphp" disabled="">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="modal_title">Anrede</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="modal_title" value="@php if($data){ echo $data[0]->title; } @endphp" autocomplete="honorific-prefix">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="modal_academic_title">Titel</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="modal_academic_title" value="@php if($data){ echo $data[0]->academic_title; } @endphp" autocomplete="honorific-prefix">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="modal_fname">Vorname</label>
<div class="col-sm-10">
<input type="name" class="form-control" id="modal_fname" value="@php if($data){ echo $data[0]->first_name; } @endphp" autocomplete="given-name">
</div>
</div>
</div>
</div>
</div>
</form>
How can I fix this error and only fill out the form with the first set/row of the collection?
I have already tried out those solutions. Not working..
value="@php if($data){ echo $data[0]->account_account_holder; } @endphp"
value="@php if($data[0){ echo $data[0]->account_account_holder; } @endphp"
value="@php if($data[0]->account_account_holder){ echo $data[0]->account_account_holder; } @endphp"