title: Can't access nested object in blade template
body: <p>I'm using Laravel, Eloquent for queries, and Blade for templating.</p>
  
  <p>Here are the models I'm working with:</p>
  
  <pre><code>namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class DistrictCharge extends Model
  {
      protected $fillable = [ 'plan_year', 'location_id', 'meal_id', 'charge_id', 'price' ];
  
      public function plan_year() {
          return $this-&gt;belongsTo('App\PlanYear', 'plan_year');
      }
  }
  
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class PlanYear extends Model
  {
      protected $fillable = [ 'year', 'start_date', 'end_date' ];
  
      public $primaryKey = 'year';
  }
  </code></pre>
  
  <p>Relevant controller code:</p>
  
  <pre><code>public function index()
  {
      $district_charges = DistrictCharge::with('plan_year')-&gt;get();
  
      return view('district-charges/index', compact(
          'district_charges',
      ));
  }
  </code></pre>
  
  <p>In my template, when I do this:</p>
  
  <pre><code>{{ $district_charges[0] }}
  </code></pre>
  
  <p>I get this (indented for readability):</p>
  
  <pre><code>{
      "id":1,
      "created_at":"2017-01-23 21:33:53",
      "updated_at":"2017-01-23 21:33:53",
      "plan_year": {
          "year":2016,
          "start_date":"2015-07-01",
          "end_date":"2016-06-30",
          "created_at":"2017-01-23 21:03:08",
          "updated_at":"2017-01-23 21:03:08"
      },
      "location_id":"2",
      "meal_id":"1",
      "charge_id":"4",
      "price":"175"
  }
  </code></pre>
  
  <p>This makes sense; the <code>plan_year</code> field is populated with the contents of the database entry it refers to, exactly as I want. But when I do this:</p>
  
  <pre><code>{{ $district_charges[0]-&gt;plan_year }}
  </code></pre>
  
  <p>I just get <code>2016</code>, a non-object. This is a problem because I queried in order to populate the <code>plan_year</code> field because I need the <code>start_date</code> and <code>end_date</code> fields that it comes with for my view. When I try to access these properties in my view I just get a 'trying to get properties of a non-object' error. I'm not that familiar with Laravel, Eloquent, or Blade, so any help would be great.</p>
  
  <p>Edit:</p>
  
  <p>Table structure as requested:</p>
  
  <pre><code>district_charges
  +-------------+------------------+------+-----+---------+----------------+
  | Field       | Type             | Null | Key | Default | Extra          |
  +-------------+------------------+------+-----+---------+----------------+
  | id          | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
  | created_at  | timestamp        | YES  |     | NULL    |                |
  | updated_at  | timestamp        | YES  |     | NULL    |                |
  | plan_year   | int(11)          | NO   |     | NULL    |                |
  | location_id | int(11)          | NO   |     | NULL    |                |
  | meal_id     | int(11)          | NO   |     | NULL    |                |
  | charge_id   | int(11)          | NO   |     | NULL    |                |
  | price       | int(11)          | NO   |     | NULL    |                |
  +-------------+------------------+------+-----+---------+----------------+
  
  plan_years
  +------------+-----------+------+-----+---------+-------+
  | Field      | Type      | Null | Key | Default | Extra |
  +------------+-----------+------+-----+---------+-------+
  | year       | int(11)   | NO   |     | NULL    |       |
  | start_date | date      | NO   |     | NULL    |       |
  | end_date   | date      | NO   |     | NULL    |       |
  | created_at | timestamp | YES  |     | NULL    |       |
  | updated_at | timestamp | YES  |     | NULL    |       |
  +------------+-----------+------+-----+---------+-------+
  </code></pre>
  
  <p>What I'm not getting is why I can see the contents of the variable I want when I output the whole thing in a template, but when I selectively output just parts of it, it says it doesn't exist.</p>