I am trying to display the User Picture in an included header template in a Laravel 8 project. Basically, I have different type of Users (Admin and Instructor) whom have different Middleware and pages. I would like to inherit the same header and display their Avatar Picture based on the User type. What I have done so far is: header.blade.php
@php
$instructor = DB::table('instructors')->where('id', Auth::guard('instructor')->user()->id)->first();
$admin = DB::table('admins')->where('id', Auth::guard('admin')->user()->id)->first();
@endphp
<!-- User Account-->
<li class="dropdown user user-menu">
<a href="#" class="waves-effect waves-light rounded dropdown-toggle p-0" data-toggle="dropdown" title="User">
@if ($admin)
<img src="{{ (!empty($admin->image))? url('upload/admin_images/'.$admin->image) : url('upload/no_image.jpg') }}" alt="">
@elseif ($instructor)
<img src="{{ (!empty($instructor->image))? url('upload/admin_images/'.$instructor->image) : url('upload/no_image.jpg') }}" alt="">
@else
<img src="{{ asset('images/1.jpg') }}" alt="">
@endif
The error is giving me is:
Trying to get property 'id' of non-object
This error is showing ONLY when I try to login as an Instructor. The Middleware, login controller for both User type are basically the same. The Instructor login is working perfectly ONLY if I completely remove the $admin variable from header.blade.php. I tried also to put in different orders the if and elseif condition but nothing changed. Does anybody has any clue on how to solve it?