hello,
try this :
@foreach ($user->userdetail as $userdetail)
<p> {{ $userdetail->phone }} </p>
@endforeach
I tried but its saying same error on this line. userdatail is null in know very well. But i want to know is there any solution to handle this issue. Because every signup user dont have detail. So whenever he came to edit page. i am using code. How to properly handle this issue by laravel.
@foreach($user->userdetail as $detail)
@forelse ($user->userdetail as $detail)
<li>{{ $detail->name }}</li>
@empty
<p>No users</p>
@endforelse
Its profile edit page and i have to show in both cases. I there is userdetail is coming from database i have to show values. If values does not exist in DB, i have to show empty text boxes. I cant use foreach. I am getting single row.
<div class="form-group">
<label class="control-label">occupation</label>
<input value="{{ $userdetail->occupation }}" type="text" name="occupation" placeholder="Design, Web etc." class="form-control">
</div>
<div class="form-group">
<label class="control-label">Company</label>
<input value="{{ $userdetail->company }}" type="text" name="company" placeholder="Seedout" class="form-control">
</div>
<div class="form-group">
<label class="control-label">Website</label>
<input value="{{ $userdetail->website}}" type="text" name="website" placeholder="http://wwww.seedout.org/" class="form-control">
</div>
is this a one to many or one to one ? one user has one user details or one user has many details?
try to use an 'if'
@if(!$user->userdetail)
<div class="form-group">
<label class="control-label">occupation</label>
<input value="" type="text" name="occupation" placeholder="Design, Web etc." class="form-control">
</div>
<div class="form-group">
<label class="control-label">Company</label>
<input value="" type="text" name="company" placeholder="Seedout" class="form-control">
</div>
<div class="form-group">
<label class="control-label">Website</label>
<input value="" type="text" name="website" placeholder="http://wwww.seedout.org/" class="form-control">
</div>
else
@foreach($user->userdetail as $detail)
<div class="form-group">
<label class="control-label">occupation</label>
<input value="{{ $userdetail->occupation }}" type="text" name="occupation" placeholder="Design, Web etc." class="form-control">
</div>
<div class="form-group">
<label class="control-label">Company</label>
<input value="{{ $userdetail->company }}" type="text" name="company" placeholder="Seedout" class="form-control">
</div>
<div class="form-group">
<label class="control-label">Website</label>
<input value="{{ $userdetail->website}}" type="text" name="website" placeholder="http://wwww.seedout.org/" class="form-control">
</div>
@endforeach
@endif
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community