title: Working with global events for models, on Laravel
body: <p><strong>It's basically what I need:</strong> if any model row on my project is <em>created</em>, <em>updated</em> or <em>removed</em>, I need call a callback to work with this model row. I'll use that to create a changelog in other model, that will not trigger this global event to avoid looping.</p>
  
  <p><strong>I tried set it like that:</strong></p>
  
  <pre><code>Model::creating($callback);
  </code></pre>
  
  <p>But it doesn't worked. Work only if I set it directly to all models that I have. It's bad because I need specific one-by-one. If I create a new one, I need specify it manually. Example:</p>
  
  <pre><code>User::creating($callback);
  Company::creating($callback);
  ...
  </code></pre>
  
  <p>Any change will be logged on another model, called <code>Log</code>. It'll not trigger this <code>$callback</code>, because it'll register on table <code>logs</code> (managed by <code>Log</code>)  each change in other models. Something like:</p>
  
  <pre><code>$user = new User;
  $user-&gt;name = "John";
  $user-&gt;age = 18;
  $user-&gt;save();
  
  $user-&gt;name = "John Doe";
  $user-&gt;save();
  
  $user-&gt;delete();
  $user-&gt;restore();
  $user-&gt;forceDelete();
  </code></pre>
  
  <p>I'll register something like:</p>
  
  <pre><code>id | object_type | object_id | event_type | object_data
  ..   App\User      1           created      { name: John, age: 18 }
  ..   App\User      1           updated      { name: John Doe }
  ..   App\User      1           trashed      null
  ..   App\User      1           restored     null
  ..   App\User      1           removed      null
  </code></pre>