Completed
Push — main ( 13c4b6...f71106 )
by Tan
18s queued 15s
created

InteractionRelationship::interactionType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace CSlant\LaravelLike\Traits;
4
5
use CSlant\LaravelLike\Models\Like;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Relations\MorphMany;
8
use Illuminate\Database\Eloquent\Relations\MorphOne;
9
10
/**
11
 * Trait InteractionRelationship
12
 *
13
 * @package CSlant\LaravelLike\Traits
14
 * @mixin Model
15
 *
16
 * @method MorphOne morphOne(string $related, string $name, string $type = null, string $id = null, string $localKey = null)
17
 * @method MorphMany morphMany(string $related, string $name, string $type = null, string $id = null, string $localKey = null)
18
 */
19
trait InteractionRelationship
20
{
21
    /**
22
     * Interaction has one relationship with the model.
23
     *
24
     * @return MorphOne
25
     */
26
    public function likeOne(): MorphOne
27
    {
28
        return $this->morphOne((string) config('like.interaction_model') ?? Like::class, 'model');
29
    }
30
31
    /**
32
     * Interaction has many relationship with the model.
33
     *
34
     * @return MorphMany
35
     */
36
    public function likes(): MorphMany
37
    {
38
        return $this->morphMany((string) config('like.interaction_model') ?? Like::class, 'model');
39
    }
40
}
41