title: Laravel Eloquent relationship data retrieve
body: <p>I have below code to get data from database,</p>
  <pre><code> $profile = Profiles::find(1);
   $currency = Profiles::find($profile-&gt;currency_id)-&gt;currency;
  
  </code></pre>
  <p>Then created a relationship in the model as below,</p>
  <pre><code>class Profiles extends Model
  {
      use HasFactory;
  
      protected $table = 'Profiles';
      protected $primaryKey = 'profile_id';
  
      public function Currency()
      {
          return $this-&gt;belongsTo(Currencies::class, 'currency_id');
      }
  }
  
  class Currencies extends Model
  {
      use HasFactory;
  
      protected $table = 'Currencies';
      protected $primaryKey = 'currency_id';
  
      public function profile()
      {
          return $this-&gt;hasOne(Profiles::class, 'currency_id');
      }
  }
  </code></pre>
  <p>Problem is that there is only 1 profile and 100 currency, <code>currency_id</code> is a foreign key in <code>Profiles</code> table,</p>
  <p>I could not get data and get this error, <code>Trying to get property 'currency' of non-object&quot;</code></p>
  <p>If i use <code> $currency = Profiles::find(1)-&gt;currency;</code> then it retrieve first row of <code>Curriencies</code> table which is not required data.</p>
  <p>How can I get currency row for that specific profile?</p>