Skip to content

Commit

Permalink
feat: custom interaction model with config
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhongit committed Sep 26, 2024
1 parent a2aeedf commit ee53d96
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions config/like.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
*/
'table_name' => 'likes',

/*
* The model class for the interaction table.
*/
'interaction_model' => 'CSlant\LaravelLike\Models\Like',

/*
* The model and foreign key for the user relationship.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/InteractionRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ trait InteractionRelationship
*/
public function likeOne(): MorphOne
{
return $this->morphOne(Like::class, 'model');
return $this->morphOne((string) config('like.interaction_model') ?? Like::class, 'model');
}

/**
Expand All @@ -35,6 +35,6 @@ public function likeOne(): MorphOne
*/
public function likes(): MorphMany
{
return $this->morphMany(Like::class, 'model');
return $this->morphMany((string) config('like.interaction_model') ?? Like::class, 'model');
}
}

0 comments on commit ee53d96

Please sign in to comment.