Completed
Push — main ( 407a1d...b509b5 )
by
unknown
17s queued 14s
created

InteractionRelationship::likes()   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
     * Like has one relationship with the model.
23
     *
24
     * @return MorphOne
25
     */
26
    public function likeOne(): MorphOne
27
    {
28
        return $this->morphOne(Like::class, 'model');
29
    }
30
31
    /**
32
     * Like has many relationship with the model.
33
     *
34
     * @return MorphMany
35
     */
36
    public function likes(): MorphMany
37
    {
38
        return $this->morphMany(Like::class, 'model');
39
    }
40
41
    /**
42
     * Get the interaction type.
43
     *
44
     * @return string
45
     */
46
    public function interactionType(): string
47
    {
48
        return $this->type->value;
49
    }
50
}
51