Support the ongoing development of Laravel.io →
Database Eloquent Views
Last updated 2 years ago.
0

hello,

try this :

@foreach ($user->userdetail as $userdetail)
   <p> {{ $userdetail->phone }} </p>
@endforeach
Last updated 7 years ago.
0

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)
Last updated 7 years ago.
0
@forelse ($user->userdetail as $detail)
    <li>{{ $detail->name }}</li>
@empty
    <p>No users</p>
@endforelse
Last updated 7 years ago.
0

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>
0

is this a one to many or one to one ? one user has one user details or one user has many details?

0

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

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.