title: Laravel firstOrCreate search for Relationship
body: <p>I want to Use firstOrCreate Function of Eloquent. The relevant part of my Data are Athletes belonging to a Nation and Nation holding many Athletes. (One to Many Relation)</p>
  
  <pre><code>class Athlete extends Model
  {
    public $timestamps = false;
    protected $fillable = ['firstname', 'lastname', 'nation'];
  .....
    public function nation()
    {
        return $this-&gt;belongsTo('App\Nation');
    }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>class Nation extends Model
  {
    public $timestamps = false;
  ...
    public function athletes()
    {
        return $this-&gt;hasMany('App\Athlete');
    }
  }
  </code></pre>
  
  <p>How can I use firstOrCreate if I also have to check for the nation?</p>
  
  <p>Neither </p>
  
  <pre><code>$ath = Athlete::firstOrCreate(['nation_id'=&gt;$nation-&gt;id, 'lastname'=&gt;$nn, 'sex'=&gt;$sex, 'firstname'=&gt;$vn] );
  </code></pre>
  
  <p>nor</p>
  
  <pre><code>$ath = Athlete::firstOrCreate(['nation'=&gt;$nation, 'lastname'=&gt;$nn, 'sex'=&gt;$sex, 'firstname'=&gt;$vn] );
  </code></pre>
  
  <p>work. </p>
  
  <p>First case: </p>
  
  <blockquote>
    <p>"Nation_id doesn't have a default value"</p>
  </blockquote>
  
  <p>Second case:</p>
  
  <blockquote>
    <p>Laravel tries to build a WHERE statement with the passed object, which
    obviously doesn't work.</p>
  </blockquote>
  
  <p>Can I use firstOrCreate here? </p>
  
  <p>THANK YOU.  </p>