Completed
Push — master ( d778e6...6d1c30 )
by ARCANEDEV
08:16
created

Role::makeSlugName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php namespace Arcanesoft\Auth\Models;
2
3
use Arcanedev\LaravelAuth\Models\Role as BaseRoleModel;
4
use Illuminate\Database\Eloquent\Builder;
5
6
/**
7
 * Class     Role
8
 *
9
 * @package  Arcanesoft\Auth\Models
10
 * @author   ARCANEDEV <[email protected]>
11
 *
12
 * @method static \Illuminate\Database\Eloquent\Builder  admin()
13
 * @method static \Illuminate\Database\Eloquent\Builder  moderator()
14
 * @method static \Illuminate\Database\Eloquent\Builder  member()
15
 */
16
class Role extends BaseRoleModel
17
{
18
    /* ------------------------------------------------------------------------------------------------
19
     |  Constants
20
     | ------------------------------------------------------------------------------------------------
21
     */
22
    const ADMINISTRATOR = 'administrator';
23
    const MODERATOR     = 'moderator';
24
    const MEMBER        = 'member';
25
26
    /* ------------------------------------------------------------------------------------------------
27
     |  Traits
28
     | ------------------------------------------------------------------------------------------------
29
     */
30
    use Presenters\RolePresenter;
31
32
    /* ------------------------------------------------------------------------------------------------
33
     |  Scopes
34
     | ------------------------------------------------------------------------------------------------
35
     */
36
    /**
37
     * Scope only with administrator role.
38
     *
39
     * @param  \Illuminate\Database\Eloquent\Builder  $query
40
     *
41
     * @return \Illuminate\Database\Eloquent\Builder
42
     */
43
    public function scopeAdmin(Builder $query)
44
    {
45
        return $query->where('slug', Role::ADMINISTRATOR);
46
    }
47
48
    /**
49
     * Scope only with moderator role.
50
     *
51
     * @param  \Illuminate\Database\Eloquent\Builder  $query
52
     *
53
     * @return \Illuminate\Database\Eloquent\Builder
54
     */
55
    public function scopeModerator(Builder $query)
56
    {
57
        return $query->where('slug', Role::MODERATOR);
58
    }
59
60
    /**
61
     * Scope only with member role.
62
     *
63
     * @param  \Illuminate\Database\Eloquent\Builder  $query
64
     *
65
     * @return \Illuminate\Database\Eloquent\Builder
66
     */
67
    public function scopeMember(Builder $query)
68
    {
69
        return $query->where('slug', Role::MEMBER);
70
    }
71
72
    /* ------------------------------------------------------------------------------------------------
73
     |  Main Function
74
     | ------------------------------------------------------------------------------------------------
75
     */
76
    /**
77
     * Get a role from a hashed id or fail if not found.
78
     *
79
     * @param  string  $hashedId
80
     *
81
     * @return self
82
     *
83
     * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
84
     */
85
    public static function firstHashedOrFail($hashedId)
86
    {
87
        return self::withHashedId($hashedId)->firstOrFail();
88
    }
89
90
    /**
91
     * Make the slug.
92
     *
93
     * @param  string  $value
94
     *
95
     * @return string
96
     */
97
    public function makeSlugName($value)
98
    {
99
        return $this->slugify($value);
100
    }
101
}
102