title: Laravel 5 Model Accessor Displayed as Undefined Variable
body: <p>I have the following laravel model class and I have an accessor to get the location name as follows (not sure if its correct syntax)</p>
  
  <pre><code>class Job extends Model {
  
      public function location()
      {
          return $this-&gt;belongsTo('App\Location');
      }
  
      public function getLocationNameAttribute()
      {
           return $this-&gt;location('name');
      }
  
  }
  </code></pre>
  
  <p>in my form I have the following:</p>
  
  <pre><code>{!! Form::text('location_name', $locationname !!}
  </code></pre>
  
  <p>But I get error Undefined variable: locationname when i try to view the page.</p>
  
  <p>The location table has two columns(id, name) and I want to get the name of the location associated with the job. How do you do this. In the job table I only store the location_id.  I can do it as follows <code>isset($job-&gt;location_id) ? $job-&gt;location-&gt;name : ''</code> but I'm trying to understand how I can achieve the same using an accessor. Can any one shed some light please.</p>