Completed
Push — master ( 50f309...1f3d4e )
by Mohamed
06:23
created

RelationTrait::issues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Model\Traits\Tag;
13
14
use Illuminate\Database\Eloquent\Relations;
15
16
/**
17
 * RelationTrait is trait class containing the relationship methods for the Tag model.
18
 *
19
 * @author Mohamed Alsharaf <[email protected]>
20
 *
21
 * @method Relations\HasMany       hasMany($related, $foreignKey = null, $localKey = null)
22
 * @method Relations\BelongsToMany belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null)
23
 * @method Relations\BelongsTo     belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
24
 */
25
trait RelationTrait
26
{
27
    /**
28
     * Returns the parent/group for the tag.
29
     *
30
     * @return Relations\BelongsTo
31
     */
32 25
    public function parent()
33
    {
34 25
        return $this->belongsTo('Tinyissue\Model\Tag', 'parent_id');
35
    }
36
37
    /**
38
     * Parent tag/group have many tags.
39
     *
40
     * @return Relations\HasMany
41
     */
42 5
    public function tags()
43
    {
44 5
        return $this->hasMany('Tinyissue\Model\Tag', 'parent_id');
45
    }
46
47
    /**
48
     * Returns issues for the Tag. Tag can belong to many issues & issue can have many tags.
49
     *
50
     * @return Relations\BelongsToMany
51
     */
52
    public function issues()
53
    {
54
        return $this->belongsToMany('Tinyissue\Model\Project\Issue', 'projects_issues_tags', 'issue_id', 'tag_id');
55
    }
56
57
    /**
58
     * Returns projects for the Tag. Tag can belong to many projects & project can have many tags.
59
     *
60
     * @return Relations\BelongsToMany
61
     */
62
    public function projects()
63
    {
64
        return $this->belongsToMany('Tinyissue\Model\Project', 'projects_kanban_tags', 'project_id', 'tag_id');
65
    }
66
}
67