laravel one to many inserting
<p>I have two models: <code>User</code> and <code>Roles</code>. I need to insert <code>User</code> and his <code>Roles</code> from same form.</p>
<pre><code>$user = new User;
$user -&gt;name = $request -&gt;input('name');
$user -&gt;email = $request -&gt;input ('email');
$user -&gt; password = $request -&gt;input ('pass');
$user -&gt;save();
$role = new Role;
$role -&gt;name = $request -&gt;input('role');
$role -&gt;explain = $request -&gt;input('exp');
$role -&gt;save();
$role -&gt;roles() -&gt;save($user);
</code></pre>
<p>It gives me an error.</p>
<p><strong><code>User</code> model:</strong></p>
<pre><code>public function roles()
{
    # code...
    return $this -&gt;hasMany('App\Role');
}
</code></pre>
<p><strong><code>Role</code> model:</strong></p>
<pre><code>public function users()
{
    # code...
    return $this -&gt;belongsTo('App\User');
}
</code></pre>
<p><strong>migrations:</strong></p>
<pre><code>   Schema::create('users', function (Blueprint $table) {
        $table-&gt;increments('id');
        $table-&gt;string('name');
        $table-&gt;string('email')-&gt;unique();
        $table-&gt;string('password', 60);
        $table-&gt;rememberToken();
        $table-&gt;timestamps();
    });
    Schema::create('roles', function (Blueprint $table) {
        $table-&gt;increments('id');
        $table-&gt;integer('user_id')-&gt;unsigned()-&gt;index();
        $table-&gt;text('name');
        $table-&gt;string('explain');
        $table-&gt;timestamps();
        //cascade
        $table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users')-    &gt;onDelete('cascade');
    });
</code></pre>
<p>I think that is the relationship is done correctly.</p>