Eloquent: Model relationship without saving to DB
<p>Say I have two Models:
User and Task</p>

<p>Their relationship is as follows:
User can have many tasks (belongsToMany) 
Task can have many users (belongsToMany) </p>

<pre><code>$user = new User();
$task = new Task();
</code></pre>

<p>Normally, I'd do something like this:
    <code>$user-&gt;tasks-&gt;attach($task)</code></p>

<p>But the problem is the User and Task is not persisted in the database. So if I run the last code above, I'll get an integrity constraint because these models have no id. </p>

<p>I have looked into the documentation and I found at that there is a method <code>associate()</code> but this requires either one of the model that has an id (saved in the database). </p>

<p>Is there any way I could attach a Model to another Model without them having persisted in the database? </p>