title: Laravel - toArray() vs getAttributes()
body: <p>I am using laravel 6 and using eloquent join to display data from multiple tables.</p>
  
  <p>Consider following code:</p>
  
  <pre><code>    $ToGetDefaultAddress 
      = TbPersonaddress::join('tb_cities AS TbCitie','TbCitie.n_CityId_PK', '=', 'tb_personaddresses.n_CityId_FK')
                      -&gt;join('tb_counties AS TbCountie','TbCountie.n_CountyId_PK', '=', 'tb_personaddresses.n_CountyId_FK')
                      -&gt;join('tb_states AS TbState', 'TbState.n_StateId_PK','=' ,'tb_personaddresses.n_StateId_FK')
                      -&gt;select('tb_personaddresses.n_PersonAddressesId_PK','tb_personaddresses.n_PersonId_FK',
                      'tb_personaddresses.d_EffectiveDateFrom','tb_personaddresses.d_EffectiveDateTo',
                      'TbCitie.s_CityCode','TbCitie.s_CityName','TbCountie.s_CountyCode',
                      'TbCountie.s_CountyName','TbState.s_StateCode','TbState.s_StateName')-&gt;first();
  
                      dd("Actual output:::::",$ToGetDefaultAddress);
  </code></pre>
  
  <p>Actual output:<a href="https://i.stack.imgur.com/gNvsz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gNvsz.png" alt="enter image description here"></a></p>
  
  <p>As shown in the above code, I am storing this output in <strong><code>$ToGetDefaultAddress</code></strong> variable.
  Now for getting only the attributes data, both <strong><code>toArray()</code></strong> and <strong><code>getAttributes()</code></strong> returns me the same result.</p>
  
  <p>For e.g:  </p>
  
  <pre><code>$DefaultAddress = $ToGetDefaultAddress-&gt;toArray();
  </code></pre>
  
  <p>and</p>
  
  <pre><code>$DefaultAddress = $ToGetDefaultAddress-&gt;getAttributes();
  </code></pre>
  
  <p>returns me the same output as shown below:
  <a href="https://i.stack.imgur.com/m8fZZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m8fZZ.png" alt="enter image description here"></a></p>
  
  <p>My question is, what is the difference between using <strong><code>toArray()</code></strong> and <strong><code>getAttributes()</code></strong> ? Which one is recommended ? When to use <strong><code>toArray()</code></strong> and when to use <strong><code>getAttributes()</code></strong> ?</p>