| Total Complexity | 5 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 17 | trait UserHasInteraction |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * Get all likes of the user. This method is used for eager loading. |
||
| 21 | * |
||
| 22 | * @return HasMany |
||
| 23 | */ |
||
| 24 | public function likes(): HasMany |
||
| 25 | { |
||
| 26 | $interactionModel = (string) (config('like.interaction_model') ?? 'CSlant\LaravelLike\Models\Like'); |
||
| 27 | $userForeignKey = (string) (config('like.users.foreign_key') ?? 'user_id'); |
||
| 28 | |||
| 29 | return $this->hasMany($interactionModel, $userForeignKey); |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Check if the user has liked the given model. |
||
| 34 | * |
||
| 35 | * @param string $interactionType |
||
| 36 | * |
||
| 37 | * @return static |
||
| 38 | */ |
||
| 39 | public function forgetInteractionsOfType(string $interactionType): static |
||
| 40 | { |
||
| 41 | $this->likes()->where('type', $interactionType)->delete(); |
||
| 42 | |||
| 43 | return $this; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Check if the user has liked the given model. |
||
| 48 | * |
||
| 49 | * @param null|string $interactionType |
||
| 50 | * |
||
| 51 | * @return static |
||
| 52 | */ |
||
| 53 | public function forgetInteractions(?string $interactionType = null): static |
||
| 62 | } |
||
| 63 | } |
||
| 64 |