Completed
Push — master ( d72a08...a4b154 )
by claudio
05:28 queued 02:49
created

Group::getPlannerNameAttribute()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4286
cc 3
eloc 3
nc 2
nop 0
crap 3
1
<?php
2
3
namespace plunner;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
/**
8
 * Class Group
9
 *
10
 * @package plunner
11
 * @author Claudio Cardinale <[email protected]>
12
 * @copyright 2015 Claudio Cardinale
13
 * @version 1.0.0
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|Employee[] $employees
23
 * @property-read Planner $planner
24
 * @property-read Company $company
25
 * @method static \Illuminate\Database\Query\Builder|\plunner\Group whereId($value)
26
 * @method static \Illuminate\Database\Query\Builder|\plunner\Group whereCreatedAt($value)
27
 * @method static \Illuminate\Database\Query\Builder|\plunner\Group whereUpdatedAt($value)
28
 * @method static \Illuminate\Database\Query\Builder|\plunner\Group whereName($value)
29
 * @method static \Illuminate\Database\Query\Builder|\plunner\Group whereDescription($value)
30
 * @method static \Illuminate\Database\Query\Builder|\plunner\Group whereCompanyId($value)
31
 * @method static \Illuminate\Database\Query\Builder|\plunner\Group wherePlannerId($value)
32
 */
33
class Group extends Model
34
{
35
    /**
36
     * The database table used by the model.
37
     *
38
     * @var string
39
     */
40
    protected $table = 'groups';
41
42
    /**
43
     * The attributes that are mass assignable.
44
     *
45
     * @var array
46
     */
47
    protected $fillable = ['name', 'description', 'planner_id'];
48
49
    /**
50
     * @var array
51
     */
52
    protected $hidden = ['planner'];
53
54
    /**
55
     * @var array
56
     */
57
    protected $appends = ['planner_name'];
58
59 14
    public function getPlannerNameAttribute()
60
    {
61 14
        if(is_object($this->planner) && $this->planner->exists)
62 14
            return $this->planner->name;
63 1
    }
64
65
    /**
66
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
67
     */
68 10
    public function employees()
69
    {
70 10
        return $this->belongsToMany(Employee::class);
71
    }
72
73
    /**
74
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
75
     */
76 14
    public function planner()
77
    {
78 14
        return $this->belongsTo(Planner::class);
79
    }
80
81
    /**
82
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
83
     */
84
    public function company()
85
    {
86
        return $this->belongsTo(Company::class);
87
    }
88
}
89