Completed
Pull Request — master (#2)
by claudio
03:56
created

Group::addEmployees()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

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 7
ccs 0
cts 7
cp 0
rs 9.4286
cc 1
eloc 4
nc 1
nop 1
crap 2
1
<?php
2
3
namespace plunner;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
/**
8
 * plunner\Group
9
 *
10
 * @property integer $id
11
 * @property \Carbon\Carbon $created_at
12
 * @property \Carbon\Carbon $updated_at
13
 * @property string $name
14
 * @property string $description
15
 * @property integer $planner_id
16
 * @property-read \Illuminate\Database\Eloquent\Collection|\plunner\Employee[] $employees
17
 * @method static \Illuminate\Database\Query\Builder|\plunner\Group whereId($value)
18
 * @method static \Illuminate\Database\Query\Builder|\plunner\Group whereCreatedAt($value)
19
 * @method static \Illuminate\Database\Query\Builder|\plunner\Group whereUpdatedAt($value)
20
 * @method static \Illuminate\Database\Query\Builder|\plunner\Group whereName($value)
21
 * @method static \Illuminate\Database\Query\Builder|\plunner\Group whereDescription($value)
22
 * @method static \Illuminate\Database\Query\Builder|\plunner\Group wherePlannerId($value)
23
 */
24
class Group extends Model
25
{
26
    /**
27
     * The database table used by the model.
28
     *
29
     * @var string
30
     */
31
    protected $table = 'groups';
32
33
    /**
34
     * The attributes that are mass assignable.
35
     *
36
     * @var array
37
     */
38
    protected $fillable = ['name', 'description'];
39
40
    public function employees()
41
    {
42
        return $this->belongsToMany('plunner\Employee', 'employee_groups');
43
    }
44
45
    public function addEmployees($employees)
46
    {
47
        $this->employees()->sync(array_map(function($employee)
48
        {
49
            return $employee->id;
50
        }), $employees);
51
    }
52
}
53