Completed
Push — master ( a0021a...b62e87 )
by claudio
14:16 queued 08:46
created

Group::employees()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace plunner;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
/**
8
 * Class Group
9
 *
10
 * @author Claudio Cardinale <[email protected]>
11
 * @copyright 2015 Claudio Cardinale
12
 * @version 1.0.0
13
 * @package plunner
14
 * @property integer $id
15
 * @property \Carbon\Carbon $created_at
16
 * @property \Carbon\Carbon $updated_at
17
 * @property string $name
18
 * @property string $description
19
 * @property integer $company_id
20
 * @property integer $planner_id
21
 * @property-read mixed $planner_name
22
 * @property-read \Illuminate\Database\Eloquent\Collection|\plunner\Employee[] $employees
23
 * @property-read \plunner\Planner $planner
24
 * @property-read \plunner\Company $company
25
 * @property-read \Illuminate\Database\Eloquent\Collection|\plunner\Meeting[] $meetings
26
 */
27
class Group extends Model
28
{
29
    /**
30
     * The attributes that are mass assignable.
31
     *
32
     * @var array
33
     */
34
    protected $fillable = ['name', 'description', 'planner_id'];
35
36
    /**
37
     * @var array
38
     */
39
    protected $hidden = ['planner', 'pivot'];
40
41
    /**
42
     * @var array
43
     */
44
    protected $appends = ['planner_name'];
45
46 54
    public function getPlannerNameAttribute()
47
    {
48 54
        if (is_object($this->planner) && $this->planner->exists)
49 54
            return $this->planner->name;
50
        return null;
51
    }
52
53
    /**
54
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
55
     */
56 48
    public function employees()
57
    {
58 48
        return $this->belongsToMany(Employee::class);
59
    }
60
61
    /**
62
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
63
     */
64 141
    public function planner()
65
    {
66 141
        return $this->belongsTo(Planner::class);
67
    }
68
69
    /**
70
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
71
     */
72
    public function company()
73
    {
74
        return $this->belongsTo(Company::class);
75
    }
76
77 117
    public function meetings()
78
    {
79 117
        return $this->hasMany(Meeting::class);
80
    }
81
}
82