Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

unk's avatar
Level 1

Trying to get property 'image' of non-object

Hello,

I have a problem with my images. Why show this error? Controller:

 public function allTimeAppointment()
    {
        $bookings = Booking::latest()->paginate(20);
        return view('admin.patientlist.index', compact('bookings'));
    }

HTML:


        <tbody>
                        @forelse($bookings as $key=>$booking)
                        <tr>
                          <th scope="row">{{$key+1}}</th>
                          <td><img src="/profile/{{$booking->user->image}}" width="80" style="border-radius: 50%;"></td>
                          <td>{{$booking->date}}</td>
                          <td>{{$booking->user->name}}</td>
                          <td>{{$booking->user->email}}</td>
                          <td>{{$booking->user->phone_number}}</td>
                          <td>{{$booking->user->gender}}</td>
                          <td>{{$booking->time}}</td>
                          <td>{{$booking->doctor->name}}</td>
                          <td>
                              @if($booking->status==0)
                              <a href="{{route('update.status', [$booking->id])}}"><button class="btn btn-primary" style="white-space: nowrap;">Pending</button></a>
                              @else 
                              <a href="{{route('update.status', [$booking->id])}}"><button class="btn btn-success" style="white-space: nowrap;">Checked</button></a>
                              @endif
                          </td>
                        </tr>
                        @empty
                        <td>You have no any appointments</td>
                        @endforelse
                       
                      </tbody>
0 likes
3 replies
unk's avatar
Level 1

@MichalOravec I don't understand exactly. I have an image for user in my database. Why doesn't show?

MichalOravec's avatar
Level 75

@unk Look to the database, column user_id is null somewhere in bookings table.

1 like

Please or to participate in this conversation.