title: Showing related table information in blade template laravel
body: <p>I have the following relationship between my tables</p>
  
  <p><img src="https://i.imgur.com/ytL1NdS.png" alt="relation"></p>
  
  <p>In my Models i have the following code:</p>
  
  <p>Location Model:</p>
  
  <pre><code>public function member() {
    return $this-&gt;belongsTo('App\Member','member_id');
   }
  </code></pre>
  
  <p>Member Model:</p>
  
  <pre><code>public function locations(){
      return $this-&gt;hasMany('App\Location','member_id');
  }
  </code></pre>
  
  <p>Now in my Location controller I created the following function.</p>
  
  <pre><code>public function getFinalData(){
      $locations = Location::with('member')-&gt;whereNotNull('member_id')-&gt;get();
      return view('locations.final-list',['locations'=&gt;$locations]);
  }
  </code></pre>
  
  <p>In my blade template however, I am unable to iterate through the member properties </p>
  
  <pre><code>&lt;ul&gt;
      @foreach($locations as $location)
        &lt;li&gt;{{$location-&gt;id}}&lt;/li&gt;
          &lt;li&gt;
           @foreach($location-&gt;member as $member)
            {{$member-&gt;id}}
           @endforeach
          &lt;/li&gt;
      @endforeach
  &lt;/ul&gt;
  </code></pre>
  
  <p>This gives me the following error:
       <strong>Trying to get property of non-object (View:locations/final-list.blade.php)</strong> </p>
  
  <p><strong>update:</strong> The result i'm trying to achieve corresponds to this query</p>
  
  <pre><code>SELECT locations.location_id,locations.name,members.first_name,          members.last_name , locations.meters
  FROM locations,members
  WHERE locations.member_id = members.id
  </code></pre>
  
  <p><strong>Update 2:</strong></p>
  
  <p>So i tried to access a single location with a single attached to it and that works perfectly</p>
  
  <pre><code>public function getFinalData(){
      //$locations = Location::with('member')-&gt;whereNotNull('member_id')-&gt;get();
      $location = Location::find(0);
  
      return view('locations.final-list',['location'=&gt;$location]);
  }
  </code></pre>
  
  <p>in final-list
  $location->member->first_name</p>
  
  <p>**Update 3 **
  Tinker Output for one record :
  <a href="https://i.stack.imgur.com/XqNNm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XqNNm.png" alt="enter image description here"></a></p>