title: How to populate the modified_by with the user_id of who made the update to the record using laravel 5.1?
body: <p>When using Laravel 5.1, I am trying to create an Observer that will automatically update the following 3 columns</p>
  
  <ol>
  <li>created_by: populate when the record in created "never update this again"</li>
  <li>modified_by: populate a new value every time a record is modified</li>
  <li>purged_by: populate a value when a record is soft deleted.</li>
  </ol>
  
  <p>I understand that Eloquent will automatically update the date time stamp (created_by, updated_at, removed_at) but I need to update the user_id that made the change.</p>
  
  <p>I was advised to use Observer and a trait to handle this. Here is what I have done</p>
  
  <p>1) created an observer class called "ModelSignature" located in <code>app\Observers\ModelSignature.php</code> and this is it's content</p>
  
  <pre><code>&lt;?php 
  
  namespace App\Observers;
  
  class ModelSignature {
  
      protected $userID;
  
      public function __construct(){
          $this-&gt;userID =  Auth::id();
      }
  
  
      public function updating($model)
      {
          $model-&gt;modified_by = $this-&gt;userID;
      }
  
  
      public function creating($model)
      {
          $model-&gt;created_by = $this-&gt;userID;
      }
  
  
      public function removing($model)
      {
          $model-&gt;purged_by = $this-&gt;userID;
      }
  
  }
  </code></pre>
  
  <p>I then created a new Trait called "RecordSignature" located in <code>app\Traits\RecordSignature.php</code> and contains the following code</p>
  
  <pre><code>&lt;?php
  
  namespace App\Traits;
  
  use app\Observers\ModelSignature;
  
  trait RecordSignature
  {
  
      public static function bootObservantTrait()
      {
          static::observe(new ModelSignature() );
      }
  }
  </code></pre>
  
  <p>Finally, in my "Account" model located on "app\Models\Account.php" I use it like this</p>
  
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\Model;
  use App\Models\industry;
  use App\Traits\RecordSignature;
  use App\Traits\TrimScalarValues;
  
  
  class Account extends Model
  {
      use RecordSignature, TrimScalarValues;
      /**
       * The database table used by the model.
       *
       * @var string
      */
      protected $table = 'accounts';
  
      protected $primaryKey = 'account_id';
  
      const CREATED_AT = 'created_on';
  
      const UPDATED_AT = 'modified_on';
  
      const REMOVED_AT = 'purged_on';
  
  
      /**
       * The attributes that are mass assignable.
       *
       * @var array
      */
      protected $fillable = ['client_id','account_name', 'company_code', 'legal_name', 'created_by','modified_by','instrucations'];
  
      /**
       * The attributes excluded from the model's JSON form.
       *
       * @var array
      */
      //protected $hidden = ['account_id', 'remember_token'];
  
  
      protected $guarded = ['account_id'];
  
      /**
       * Get the industry record associated with the account.
      */
      public function industry()
      {
          return $this-&gt;hasOne(industry, industry::primaryKey);
      }
  
      public function pk(){
  
          return $this-&gt;primaryKey;
      }
  
  }
  </code></pre>
  
  <p>The problem is that the methods <code>updating()</code>, <code>removing()</code> and <code>creating()</code> are not populating the userId as expected. It seems that the fields are being ignored or the methods are not being fired!</p>
  
  <p>What am I doing wrong here?</p>