title: Trying to get property 'image' of non-object in Laravel
body: <p>I am working on a laravel project. In this project, when i try to view and edit the profile page. I am getting this error.</p>
  <p>ErrorException
  Trying to get property 'image' of non-object (View: C:\xampp\htdocs\HomeServices\resources\views\livewire\sprovider\sprovider-profile-component.blade.php)
  <a href="http://127.0.0.1:8000/sprovider/profile" rel="nofollow noreferrer">http://127.0.0.1:8000/sprovider/profile</a></p>
  <p>SproviderProfileComponent.php :-</p>
  <pre><code>&lt;?php
  
  namespace App\Http\Livewire\Sprovider;
  
  use App\Models\ServiceProvider;
  use Illuminate\Support\Facades\Auth;
  use Livewire\Component;
  
  class SproviderProfileComponent extends Component
  {
      public function render()
      {
          $sprovider = ServiceProvider::where('user_id',Auth::user()-&gt;id)-&gt;first();
          return view('livewire.sprovider.sprovider-profile-component',['sprovider'=&gt;$sprovider])-&gt;layout('layouts.base');
      }
  }
  </code></pre>
  <p>Models/ServiceProvider.php :-</p>
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\Factories\HasFactory;
  use Illuminate\Database\Eloquent\Model;
  
  class ServiceProvider extends Model
  {
      use HasFactory;
  
      protected $fillable = ['user_id'];
  
      public function category()
      {
          return $this-&gt;belongsTo(ServiceCategory::class,'service_category_id');
      }
  }
  </code></pre>
  <p>sprovider-profile-component.blade.php</p>
  <pre><code>&lt;div class=&quot;panel-body&quot;&gt;
      &lt;div class=&quot;row&quot;&gt;
          &lt;div class=&quot;col-md-4&quot;&gt;
              @if($sprovider-&gt;image)
                  &lt;img src=&quot;{{asset('images/sproviders')}}/{{$sprovider-&gt;image}}&quot; width=&quot;100%&quot; /&gt;
              @else
                  &lt;img src=&quot;{{asset('images/sproviders/default.jpg')}}&quot; width=&quot;100%&quot; /&gt;
              @endif
          &lt;/div&gt;
              &lt;div class=&quot;col-md-8&quot;&gt;
                  &lt;h3&gt;Name: {{Auth::user()-&gt;name}}&lt;/h3&gt;
                  &lt;p&gt;{{$sprovider-&gt;about}}&lt;/p&gt;
                  &lt;p&gt;&lt;b&gt;Email: &lt;/b&gt;{{Auth::user()-&gt;email}}&lt;/p&gt;
                  &lt;p&gt;&lt;b&gt;Phone: &lt;/b&gt;{{Auth::user()-&gt;phone}}&lt;/p&gt;
                  &lt;p&gt;&lt;b&gt;City: &lt;/b&gt;{{$sprovider-&gt;city}}&lt;/p&gt;
                  &lt;p&gt;&lt;b&gt;Service Category: &lt;/b&gt;
                  @if($sprovider-&gt;service_category_id)
                      {{$sprovider-&gt;category-&gt;name}}
                  @endif
                  &lt;/p&gt;
                  &lt;p&gt;&lt;b&gt;Service Locations: {{$sprovider-&gt;service_locations}}&lt;/b&gt;&lt;/p&gt;
                  &lt;a href=&quot;{{route('sprovider.edit_profile')}}&quot; class=&quot;btn btn-info pull-right&quot;&gt;Edit Profile&lt;/a&gt;
              &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>