Laravel eloquent - inserting into related tables together
<p>I searched for this and got a lot of results and everyone says it works.</p>

<p>My situation is exactly the same as shown here <a href="http://laravel.io/forum/04-22-2015-hasone-and-insert" rel="nofollow">http://laravel.io/forum/04-22-2015-hasone-and-insert</a></p>

<pre><code>Schema::create('devices', function(Blueprint $table)
    {
        $table-&gt;increments('id');
        $table-&gt;string('token')-&gt;unique();
        $table-&gt;enum('type', ['android', 'ios']);
        $table-&gt;timestamps();

    });
Schema::create('students', function(Blueprint $table)
    {
        $table-&gt;increments('id');
        $table-&gt;string('nom', 15);
        $table-&gt;integer('device_id')-&gt;unsigned();
        $table-&gt;timestamps();

        $table-&gt;foreign('device_id')-&gt;references('id')-&gt;on('devices')-&gt;onDelete('cascade');
    });
</code></pre>

<p>Student Model</p>

<pre><code>public function device() {
    return $this-&gt;hasOne('App\Device');
}
</code></pre>

<p>Device Model</p>

<pre><code>public function user()
{
    return $this-&gt;belongsTo('App\Etudiant');
}
</code></pre>

<p>And I tried</p>

<pre><code>$student = Student::create(['nom' =&gt; $nom, 'type' =&gt; $type]);
$student-&gt;device()-&gt;create(['token' =&gt; $token]);
$student-&gt;save();
</code></pre>

<p>But i'm getting error <code>Call to undefined method Illuminate\Database\Query\Builder::create()
</code> for <code>$student-&gt;device()-&gt;create(['token' =&gt; $token]);</code></p>