title: Undefined property: stdClass::$**** in One to Many Relationships Laravel 5
body: <p>I am new to Laravel and I am creating a Laravel5 project where the Voters is related to a City in one to many relationships: every voter has only one City while City has many voters</p>
  
  <p>My Table looks like this</p>
  
  <p>//voters</p>
  
  <pre><code>Id Name City_id
  </code></pre>
  
  <p>//city</p>
  
  <pre><code>Id Name 
  </code></pre>
  
  <p>And inside App/Models</p>
  
  <p>//city.php</p>
  
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\Model;
  
  class City extends Model
  {
  /**
  *The table associated with the model
  *
  */
  protected $table = 'city';
  
  /**
  * indicates if the model should be timestamped
  * @var bool
  */
  
  public $timestamps = false;
  
   public function voters()
   {
      return $this-&gt;belongsTo('App\models\Voters');
   }
  }
  </code></pre>
  
  <p>voters.php</p>
  
  <pre><code> &lt;?php
  
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Voters extends Model
  {
   protected $table = 'voters';
  
   public function city()
   {
      return $this-&gt;hasMany('App\Models\City');
   }
  }
  </code></pre>
  
  <p>I can accessed all voters in the controller this way</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  use Illuminate\Http\Request;
  use App\Http\Requests;
  use App\Http\Controllers\Controller;
  use DB;
  
  class VotersController extends Controller
  {
  /**
   * Display a listing of the resource.
   *
   * @return \Illuminate\Http\Response
   */
    public function index()
    {
       $voters = DB::table('voters')-&gt;get();
       return view('voters.all_voters',['voters' =&gt; $voters] );
    }
   }
  </code></pre>
  
  <p>But the problem is the voter's city return an error </p>
  
  <pre><code>Undefined property: stdClass::$city (View: .....
  </code></pre>
  
  <p>The blade template</p>
  
  <pre><code>&lt;div class="table-responsive"&gt;
  &lt;table class="table table-hover table-bordered table-condensed"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Name&lt;/th&gt;
              &lt;th&gt;Age&lt;/th&gt;
              &lt;th&gt;Profession&lt;/th&gt;
              &lt;th&gt;City&lt;/th&gt;
              &lt;th&gt;Province&lt;/th&gt;
              &lt;th&gt;Region&lt;/th&gt;
              &lt;th&gt;Island&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          @foreach($voters as $voter)
          &lt;tr&gt;
              &lt;td&gt;{{ $voter-&gt;firstname }}&lt;/td&gt;
              &lt;td&gt;{{ $voter-&gt;birthday }}&lt;/td&gt;
              &lt;td&gt;{{ $voter-&gt;profession_id }}&lt;/td&gt;
              &lt;td&gt;{{ $voters-&gt;city_id }} &lt;/td&gt;//returnm the city_id but I want the city name in this case
              &lt;td&gt;{{ $voter-&gt;city-&gt;name }}&lt;/td&gt;//
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;&lt;/td&gt;
          &lt;/tr&gt;
          @endforeach
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>How to properly display related field for this kind of relationships in Laravel?    </p>
  
  <p>Update</p>
  
  <p>Upon checking the property</p>
  
  <pre><code> @if(isset($voter-&gt;city))
      {{ $voter-&gt;city-&gt;name }}
    @endif
  </code></pre>
  
  <p>Throws no error but the city return no values
  The result shows that city is not set.</p>