Laravel - create object with belongsTo relationship
<p>I am using Laravel 5.2 and I have associated an usergroup to any user with a belongsTo relationship. Now I want to create users with the correct relationship. Is there any possibility to take the correct relationship into to create method?</p>

<p>For example, my current code updates the object after creation:</p>

<pre><code>$usergroup = Usergroup::findOrFail($usergroupId);

$user = User::create([
        'email' =&gt; $request-&gt;email,
        'password' =&gt; bcrypt($request-&gt;password) ]);
$user-&gt;usergroup()-&gt;associate($usergroup);
$user-&gt;save();
</code></pre>

<p>It works, but it isn't a pretty solution. I tried some things but none worked. I want something like:</p>

<pre><code>$usergroup = Usergroup::findOrFail($usergroupId);

$user = User::create([
        'email' =&gt; $request-&gt;email,
        'password' =&gt; bcrypt($request-&gt;password)
        'usergroup' =&gt; $usergroup ]); // does not work!
</code></pre>