sebastiankennedy /
laravel-like
| 1 | <?php |
||||
| 2 | |||||
| 3 | /* |
||||
| 4 | * This file is part of the sebastian-kennedy/laravel-like. |
||||
| 5 | * |
||||
| 6 | * (c) SebastianKennedy <[email protected]> |
||||
| 7 | * |
||||
| 8 | * This source file is subject to the MIT license that is bundled. |
||||
| 9 | */ |
||||
| 10 | |||||
| 11 | namespace SebastianKennedy\LaravelLike\Behaviors; |
||||
| 12 | |||||
| 13 | use Illuminate\Database\Eloquent\Model; |
||||
| 14 | |||||
| 15 | trait CanBeLikedBehavior |
||||
| 16 | { |
||||
| 17 | 3 | public function isLikedBy(Model $user) |
|||
| 18 | { |
||||
| 19 | 3 | if (is_a($user, config('auth.providers.users.model'))) { |
|||
| 20 | 3 | if ($this->relationLoaded('likers')) { |
|||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 21 | 3 | return $this->likers->contains($user); |
|||
| 22 | } |
||||
| 23 | |||||
| 24 | 3 | return ($this->relationLoaded('likes') ? $this->likes : $this->likes()) |
|||
| 25 | 3 | ->where(config('like.foreign_key'), $user->getKey()) |
|||
| 26 | 3 | ->count() > 0; |
|||
| 27 | } |
||||
| 28 | |||||
| 29 | 3 | return false; |
|||
| 30 | } |
||||
| 31 | |||||
| 32 | 15 | public function likes() |
|||
| 33 | { |
||||
| 34 | 15 | return $this->morphMany(config('like.model'), config('like.morph_many_name')); |
|||
|
0 ignored issues
–
show
It seems like
morphMany() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 35 | } |
||||
| 36 | |||||
| 37 | 6 | public function likers() |
|||
| 38 | { |
||||
| 39 | 6 | return $this->belongsToMany( |
|||
|
0 ignored issues
–
show
It seems like
belongsToMany() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 40 | 6 | config('auth.providers.users.model'), |
|||
| 41 | 6 | config('like.table_name'), |
|||
| 42 | 6 | config('like.morph_many_id'), |
|||
| 43 | 6 | config('like.foreign_key') |
|||
| 44 | 6 | )->where(config('like.morph_many_type'), $this->getMorphClass()); |
|||
|
0 ignored issues
–
show
It seems like
getMorphClass() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 45 | } |
||||
| 46 | } |
||||
| 47 |