title: How to add an sql function to a laravel eloquent model
body: <p>I'm wanting to create a laravel model with a computed column. I've seen how to do this once the data is downloaded however the computation I wish to do is expensive but accessible as a function in my sql. Essentially I'd like to append one more column to the query builder but I'm unsure how to go about it.</p>
  
  <p>The query needs to be something like:</p>
  
  <pre><code>select *, my_function(ID) as my_value from my_table;
  </code></pre>
  
  <p>and I need to get an instance of the model in return (not a raw recordset).</p>
  
  <p>I'm also hoping to avoid multiple queries.</p>
  
  <p>Thanks.</p>