title: LARAVEL 7 || Trying to get property 'name' of non-object
body: <p>I tried to get the name from the author table but this error always happens. What should I do?</p>
  
  <p><strong>MODEL</strong>
  <em>App\Book</em></p>
  
  <pre><code>public function author()
      {
          return $this-&gt;hasOne('App\Author');
      }
  </code></pre>
  
  <p><em>App\Author</em></p>
  
  <pre><code>public function book()
  {
         return $this-&gt;belongsTo('App\Book');
  }
  </code></pre>
  
  <p><strong>Views</strong>
  <em>Author/show...</em></p>
  
  <pre><code>   @php 
          $book = Book::with('author')-&gt;where('author_id',$author-&gt;id)-&gt;get();
     @endphp`
     @foreach ($book as $data)
  
         ...
            Author name : {{$data-&gt;author_id-&gt;name}}
         ...
  
     @endforeach
  </code></pre>