Extending Tailor model with customer methods

Hi everyone,

Is there a way to extend tailor models to have a custom method?

For example, a blueprint has firstName and LastName fields, and I want to add a method in the model class to return firstName + ’ ’ + ‘lastName’

I tried the following with no luck

EntryRecord::extendInSection('ACME\Customer', function($model) {
  

  $model->bindEvent('model.extendBlueprint', function () use ($model) {
      $model->fullname = $model->firstname . ' ' . $model->lastname;
  });

});

Any ideas?
Thanks a lot,

Abbas

I was able to achieve that by biding the new property to the model.afterFetch event:

EntryRecord::extendInSection('ACME\Customer', function($model) {
 
  $model->bindEvent('model.afterFetch', function () use ($model) {
      $model->fullname = $model->firstname . ' ' . $model->lastname;
  });

});
2 Likes

A better way to extend Tailor Models is mentioned here