Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

orest's avatar
Level 13

determine if model is recordable

I have a trait that records the activity of a model

RecordsActivityTrait

One of the models is polymorphic and in some cases i don't want to record the activity for that particular case.

The model name is Reply and it has a repliable relationship

For example

if ( $reply->repliable_type == 'SomeName' ){
 // activity should not be recorded    
}

Now i'm wondering if i should create a method isRecordable for all models that i want to record the activity

public function isRecordable()
{
     return true;
}

And for the Reply model it would be

public function isRecordable()
{
    if ( $this->repliable_type == 'SomeName' ){
         return false;
     }
     return true;
}
}

or should i create a class that determines if the model is recordable

For example

class DetermineRecordability
{
     public function handle($model)
      {
               if ( class_basename($model) == 'Reply' && $model->repliable_type == 'SomeName'){
                    return false;
               }
               return true;
       }
}

Which approach do you think is better ?

0 likes
2 replies
wingly's avatar

You can probably do it with a lot of ways for example you can create an interface Recordable that a model which needs to be recorded implements then check if the repliable is recordable (using for example instanceof Recordable) and do your recording stuff

1 like
orest's avatar
Level 13

@wingly thanks for the suggestion

i thought of that but it doesn't depend only on the repliable model. There is a case where it depends on another column of the replies table.

Please or to participate in this conversation.