Completed
Push — develop-3.0 ( 360277...bd5ff0 )
by Mohamed
06:52
created

TagRelations::projects()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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;
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
 * @property static $this
22
 */
23
trait TagRelations
24
{
25
    /**
26
     * Returns the parent/group for the tag.
27
     *
28
     * @return Tag
29
     */
30
    public function parent()
31
    {
32
        return $this->belongsTo(Tag::class, 'parent_id');
33
    }
34
35
    /**
36
     * Parent tag/group have many tags.
37
     *
38
     * @return Tag
39
     */
40
    public function tags()
41
    {
42
        return $this->hasMany(Tag::class, 'parent_id');
43
    }
44
45
    /**
46
     * Relation to tags that are accessible to current logged user.
47
     *
48
     * @return Tag
49
     */
50
    public function userAccessibleTags()
51
    {
52
        return $this->tags()->accessibleToLoggedUser();
53
    }
54
55
    /**
56
     * Returns issues for the Tag. Tag can belong to many issues & issue can have many tags.
57
     *
58
     * @return Project\Issue
59
     */
60
    public function issues()
61
    {
62
        return $this->belongsToMany(Project\Issue::class, 'projects_issues_tags', 'issue_id', 'tag_id');
63
    }
64
65
    /**
66
     * Returns projects for the Tag. Tag can belong to many projects & project can have many tags.
67
     *
68
     * @return Project
69
     */
70
    public function projects()
71
    {
72
        return $this->belongsToMany(Project::class, 'projects_kanban_tags', 'project_id', 'tag_id');
73
    }
74
75
    abstract public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null);
76
77
    abstract public function hasMany($related, $foreignKey = null, $localKey = null);
78
79
    abstract public function belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null);
80
}
81