Overriding model factory defaults with a dynamically computed property
<p>Disclaimer: Almost zero experience with PHP.</p>

<p>Using ‘tinker’… I have created (and persistent) two user models with ids 1,2 respectively. Now, I want to create a number of posts (Post model) and I want to override the default attributes such that it will be a random number between 1 and 2 (as per the user ids). </p>

<p>How can I achieve this? I can’t really pass to the overrides array something like     </p>

<pre><code>[‘user_id’ =&gt; rand( 1, 2 )] 
</code></pre>

<p>as this will only be computed once and thus, all posts will have the same user. Also, i don't want to override the attribute within the ModelFactory.php as i want the user_id range to be dynamically computed. </p>

<p>Thanks in advance. </p>

<p>SK</p>