Skip to content

Commit

Permalink
feat: create the new attribute to get interaction type of Like
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhongit committed Sep 26, 2024
1 parent 13c4b66 commit 5a971b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
12 changes: 12 additions & 0 deletions src/Models/Like.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* @property InteractionTypeEnum $type
* @property Carbon $created_at
* @property Carbon $updated_at
*
* @property-read string $interaction_type getInteractionTypeAttribute()
*/
class Like extends Model
{
Expand Down Expand Up @@ -96,4 +98,14 @@ public function scopeWithModelType(Builder $query, string $modelType): Builder
// Use with likes() relationship. Can't use with likeOne() relationship.
return $query->where('model_type', app($modelType)->getMorphClass());
}

/**
* Get the interaction type attribute. Used for the accessor.
*
* @return string
*/
public function getInteractionTypeAttribute(): string
{
return $this->type->value;
}
}
10 changes: 0 additions & 10 deletions src/Traits/InteractionRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,4 @@ public function likes(): MorphMany
{
return $this->morphMany(Like::class, 'model');
}

/**
* Get the interaction type.
*
* @return string
*/
public function interactionType(): string
{
return $this->type->value;
}
}

0 comments on commit 5a971b0

Please sign in to comment.