title: How to set attributes with accessors into a model properly in Laravel?
body: <pre><code>class Theme
  {
      public function getNameAttribute()
      {
          return 'prefix-' . $this-&gt;id;
      }
  }
  
  
  $theme = Theme::find(1);
  
  dump($theme-&gt;name); // "prefix-1"
  
  $array = $theme-&gt;toArray();
  
  dump($array) // ["id" =&gt; 1]
  </code></pre>
  
  <p>The "name" attribute does not appear in the array, so I have to add the following code (or add <code>$theme-&gt;name = ''</code> before <code>toArray()</code>):</p>
  
  <pre><code>$array['name'] = $theme-&gt;name;
  
  dump($array) // ["id" =&gt; 1, "name" =&gt; "prefix-1"]
  
  return $array;
  </code></pre>
  
  <p>Is there any other way to do this more elegantly?</p>