title: Create a single mutator for multple fields using laravel 5.6
body: <p>I want to create a mutator that will serve me for several fields of a table. I have several fields called: h1, h2, h3 and other fields.</p>
  
  <p>For now I have a mutator for each field (h1, h2 and h3) that works as follows:</p>
  
  <p>If there is a value, that value is inserted in the field h1, h2 or h3, but if not, a 0 is inserted</p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Custom extends Model
  {
     protected $fillable = array(
        'h1', 'h2', 'h3', 'other_field', 'other_field2'
     );
  
    public function setH1Attribute($value)
    {
      if(!empty($value))
          $this-&gt;attributes['h1'] = $value;
      else
          $this-&gt;attributes['h1'] = 0;
    }
  
    public function setH2Attribute($value)
    {
      if(!empty($value))
          $this-&gt;attributes['h2'] = $value;
      else
          $this-&gt;attributes['h2'] = 0;
    }
  
    public function setH3Attribute($value)
    {
      if(!empty($value))
          $this-&gt;attributes['h3'] = $value;
      else
          $this-&gt;attributes['h3'] = 0;
    }
  }
  </code></pre>
  
  <p>How can I create a single mutator that speeds up this task but only for the fields h1, h2, h3  and that I ignore the other fields?</p>
  
  <p>Thanks for the help</p>