title: Laravel: performing some task on every insert/update when using Query Builder or Eloquent ORM
body: <h2>The Problem</h2>
  
  <p>I would like to automatically add <code>created_by</code> and <code>modified_by</code> fields to every insert/update to a database table in Laravel 4, regardless of whether I am using Eloquent or Query Builder. However, not all my tables have these fields so any solution will have to check these columns exist before adding.</p>
  
  <h2>Attempted Solution</h2>
  
  <p>I have extended the <a href="https://github.com/illuminate/database/blob/master/Eloquent/Model.php" rel="noreferrer"><code>Illuminate\Database\Eloquent\Model</code></a> class and written an overwrite method <code>save()</code> in order to add some additional meta data fields for every record that is saved.</p>
  
  <p>This is fine except that if I perform an insert using the Query Builder then this is bypassed. Looking at the <code>Model</code> class it appears that the database operations are actually done using the query builder.</p>
  
  <p>I have had a look at the <a href="https://github.com/illuminate/database/blob/master/Query/Builder.php" rel="noreferrer"><code>Illuminate\Database\Query\Builder</code></a> model and it looks like I could probably write overwrite methods for <code>insert()</code> and <code>update()</code>.</p>
  
  <p>Is this a sensible way to go about performing some task for every insert/update or will I run into trouble later down the line?</p>