title: Laravel - Helper file with function calls an accessor
body: <p>I have an helper file with my functions accessible from all parts of the project.</p>
  <p>In these functions I have one that call an accessor from a model, but I get error when used.</p>
  <p>Here the function:</p>
  <pre><code>function placeholder_decode($placeholder, $documento)
  {
      $variables['#document.protocol_number_view#'] = $documento-&gt;protocol_number_view;
      
      $string = json_decode(str_replace(array_keys($variables), array_values($variables), $placeholder));
  
      return $string[0]-&gt;value;
  
  }
  </code></pre>
  <p>The accessor is the call to <code>$documento-&gt;protocol_number_view</code>.</p>
  <p>This is the code of the accessor into model code:</p>
  <pre><code>public function getProtocolNumberViewAttribute()
  {
      $format = Configuration::select(&quot;value&quot;)-&gt;where(&quot;company_id&quot;, $this-&gt;attributes['company_id'])-&gt;where(&quot;name&quot;, &quot;prot_format&quot;)-&gt;get();
  
      if ($this-&gt;attributes['protocol_number'] != 0) {
          $number = placeholder_decode($format, $this);
      } else {
          $number = &quot;&quot;;
      }
      return $number;
  }
  </code></pre>
  <p>This is the error I got:</p>
  <pre><code>[2021-03-10 20:27:54] local.ERROR: ErrorException: Undefined property: App\Document::$protocol_number_view in /var/www/protocol/app/helpers.php:15
  </code></pre>
  <p>This is the result of dd($documento) into placeholder_decode() function:</p>
  <pre><code>App\Document {#939
    #table: &quot;documents&quot;
    #fillable: array:13 [
      0 =&gt; &quot;company_id&quot;
      1 =&gt; &quot;date&quot;
      2 =&gt; &quot;type&quot;
      3 =&gt; &quot;subject&quot;
      4 =&gt; &quot;senderable_type&quot;
      5 =&gt; &quot;senderable_id&quot;
      6 =&gt; &quot;protocol_number&quot;
      7 =&gt; &quot;protocol_date&quot;
      8 =&gt; &quot;is_reserved&quot;
      9 =&gt; &quot;cancelled&quot;
      10 =&gt; &quot;created_user_id&quot;
      11 =&gt; &quot;updated_user_id&quot;
      12 =&gt; &quot;deleted_user_id&quot;
    ]
    #dates: array:3 [
      0 =&gt; &quot;date&quot;
      1 =&gt; &quot;protocol_date&quot;
      2 =&gt; &quot;deleted_at&quot;
    ]
    #appends: array:1 [
      0 =&gt; &quot;protocol_number_view&quot;
    ]
    #connection: &quot;mysql&quot;
    #primaryKey: &quot;id&quot;
    #keyType: &quot;int&quot;
    +incrementing: true
    #with: []
    #withCount: []
    #perPage: 15
    +exists: true
    +wasRecentlyCreated: false
    #attributes: array:17 [
      &quot;id&quot; =&gt; 4
      &quot;company_id&quot; =&gt; 1
      &quot;date&quot; =&gt; &quot;2020-11-03 19:51:14&quot;
      &quot;type&quot; =&gt; &quot;E&quot;
      &quot;subject&quot; =&gt; &quot;Richiesta Trofeo&quot;
      &quot;senderable_type&quot; =&gt; &quot;App\Address&quot;
      &quot;senderable_id&quot; =&gt; 18
      &quot;protocol_number&quot; =&gt; 10
      &quot;protocol_date&quot; =&gt; &quot;2021-03-10 18:45:50&quot;
      &quot;is_reserved&quot; =&gt; 0
      &quot;cancelled&quot; =&gt; 0
      &quot;created_user_id&quot; =&gt; 1
      &quot;updated_user_id&quot; =&gt; 1
      &quot;deleted_user_id&quot; =&gt; null
      &quot;created_at&quot; =&gt; &quot;2020-11-03 19:51:14&quot;
      &quot;updated_at&quot; =&gt; &quot;2021-03-10 18:45:50&quot;
      &quot;deleted_at&quot; =&gt; null
    ]
    #original: array:17 [
      &quot;id&quot; =&gt; 4
      &quot;company_id&quot; =&gt; 1
      &quot;date&quot; =&gt; &quot;2020-11-03 19:51:14&quot;
      &quot;type&quot; =&gt; &quot;E&quot;
      &quot;subject&quot; =&gt; &quot;Richiesta Trofeo&quot;
      &quot;senderable_type&quot; =&gt; &quot;App\Address&quot;
      &quot;senderable_id&quot; =&gt; 18
      &quot;protocol_number&quot; =&gt; 10
      &quot;protocol_date&quot; =&gt; &quot;2021-03-10 18:45:50&quot;
      &quot;is_reserved&quot; =&gt; 0
      &quot;cancelled&quot; =&gt; 0
      &quot;created_user_id&quot; =&gt; 1
      &quot;updated_user_id&quot; =&gt; 1
      &quot;deleted_user_id&quot; =&gt; null
      &quot;created_at&quot; =&gt; &quot;2020-11-03 19:51:14&quot;
      &quot;updated_at&quot; =&gt; &quot;2021-03-10 18:45:50&quot;
      &quot;deleted_at&quot; =&gt; null
    ]
    #changes: []
    #casts: []
    #classCastCache: []
    #dateFormat: null
    #dispatchesEvents: []
    #observables: []
    #relations: array:2 [
      &quot;company&quot; =&gt; App\Company {#954
        #table: &quot;companies&quot;
        #fillable: array:4 [
          0 =&gt; &quot;name&quot;
          1 =&gt; &quot;created_user_id&quot;
          2 =&gt; &quot;updated_user_id&quot;
          3 =&gt; &quot;deleted_user_id&quot;
        ]
        #connection: &quot;mysql&quot;
        #primaryKey: &quot;id&quot;
        #keyType: &quot;int&quot;
        +incrementing: true
        #with: []
        #withCount: []
        #perPage: 15
        +exists: true
        +wasRecentlyCreated: false
        #attributes: array:8 [
          &quot;id&quot; =&gt; 1
          &quot;name&quot; =&gt; &quot;Federazione&quot;
          &quot;created_user_id&quot; =&gt; null
          &quot;updated_user_id&quot; =&gt; null
          &quot;deleted_user_id&quot; =&gt; null
          &quot;created_at&quot; =&gt; &quot;2020-10-08 18:45:47&quot;
          &quot;updated_at&quot; =&gt; &quot;2020-10-08 18:45:47&quot;
          &quot;deleted_at&quot; =&gt; null
        ]
        #original: array:8 [
          &quot;id&quot; =&gt; 1
          &quot;name&quot; =&gt; &quot;Federazione&quot;
          &quot;created_user_id&quot; =&gt; null
          &quot;updated_user_id&quot; =&gt; null
          &quot;deleted_user_id&quot; =&gt; null
          &quot;created_at&quot; =&gt; &quot;2020-10-08 18:45:47&quot;
          &quot;updated_at&quot; =&gt; &quot;2020-10-08 18:45:47&quot;
          &quot;deleted_at&quot; =&gt; null
        ]
        #changes: []
        #casts: []
        #classCastCache: []
        #dates: array:1 [
          0 =&gt; &quot;deleted_at&quot;
        ]
        #dateFormat: null
        #appends: []
        #dispatchesEvents: []
        #observables: []
        #relations: []
        #touches: []
        +timestamps: true
        #hidden: []
        #visible: []
        #guarded: array:1 [
          0 =&gt; &quot;*&quot;
        ]
        #forceDeleting: false
      }
      &quot;tags&quot; =&gt; Illuminate\Database\Eloquent\Collection {#919
        #items: []
      }
    ]
    #touches: []
    +timestamps: true
    #hidden: []
    #visible: []
    #guarded: array:1 [
      0 =&gt; &quot;*&quot;
    ]
    #forceDeleting: false
    #queuedTags: []
  }
  </code></pre>