title: Autofill field in a laravel model?
body: <p>In my laravel app, a simple eloquent call generates a new id for the new item in my table. <code>$Article = new Article;</code> </p>
  
  <p>If I wanted to also generate a custom code at the same time, how would I do that?</p>
  
  <p>I tried this: </p>
  
  <pre><code>protected $fillable = [
  'RandomReference' =&gt; substr(md5(rand()), 0, 7),
  ...
  </code></pre>
  
  <p>but get this error:  <code>Constant expression contains invalid operations</code></p>
  
  <p>Doesn't help if I make it a protected field (rather than fillable) either. </p>