Completed
Push — master ( f8a22c...480ba6 )
by ARCANEDEV
12s
created

Activatable::activate()   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
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php namespace Arcanedev\LaravelAuth\Models\Traits;
2
3
/**
4
 * Class     Activatable
5
 *
6
 * @package  Arcanedev\LaravelAuth\Traits
7
 * @author   ARCANEDEV <[email protected]>
8
 *
9
 * @property  bool  is_active
10
 *
11
 * @method    bool  save(array $options = [])
12
 */
13
trait Activatable
14
{
15
    /* -----------------------------------------------------------------
16
     |  Main Methods
17
     | -----------------------------------------------------------------
18
     */
19
20
    /**
21
     * Activate/deactivate the model.
22
     *
23
     * @param  bool  $active
24
     * @param  bool  $save
25
     *
26
     * @return bool
27
     */
28 9
    protected function switchActive($active, $save = true)
29
    {
30 9
        $this->forceFill(['is_active' => boolval($active)]);
31
32 9
        return $save ? $this->save() : false;
33
    }
34
35
    /**
36
     * Fill the model with an array of attributes. Force mass assignment.
37
     *
38
     * @param  array  $attributes
39
     *
40
     * @return self
41
     */
42
    abstract public function forceFill(array $attributes);
43
44
    /* -----------------------------------------------------------------
45
     |  Check Methods
46
     | -----------------------------------------------------------------
47
     */
48
49
    /**
50
     * Check if the model is active.
51
     *
52
     * @return bool
53
     */
54 75
    public function isActive()
55
    {
56 75
        return $this->is_active;
57
    }
58
}
59