title: Laravel PHP Traits with models
body: <p>I have a PHP trait that I will use in any model that can do a certain set of actions. For example one of these actions is completion where completed_at is marked with a timestamp.</p>
  
  <p>The trait method is:</p>
  
  <pre><code>/**
   * @return $this
   * @throws Exception
   */
  public function markCompleted(){
      if($this-&gt;canDoAction('complete')){
          $this-&gt;completed_at = Carbon::now();
          return $this;
      }
  }
  </code></pre>
  
  <p>In my controller I am calling this on a model that can do this action like below.</p>
  
  <pre><code>$app-&gt;markCompleted()-&gt;save();
  </code></pre>
  
  <p>The $app when I view its contents it is not null.</p>
  
  <p>Running this command returns an error like </p>
  
  <pre><code>local.ERROR: Call to a member function save() on null
  </code></pre>
  
  <p>Wouldn't $this represent the model that uses this trait?</p>