Completed
Pull Request — master (#1)
by ARCANEDEV
04:05
created

Permission::group()   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 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php namespace Arcanedev\LaravelAuth\Models;
2
3
use Arcanedev\LaravelAuth\Bases\Model;
4
use Arcanedev\LaravelAuth\Traits\AuthPermissionRelationships;
5
use Arcanedev\LaravelAuth\Traits\AuthRoleTrait;
6
use Arcanedev\LaravelAuth\Traits\Slugable;
7
use Arcanesoft\Contracts\Auth\Models\Permission as PermissionContract;
8
9
/**
10
 * Class     Permission
11
 *
12
 * @package  Arcanedev\LaravelAuth\Models
13
 * @author   ARCANEDEV <[email protected]>
14
 *
15
 * @property  int                                            id
16
 * @property  int                                            group_id
17
 * @property  string                                         name
18
 * @property  string                                         slug
19
 * @property  string                                         description
20
 * @property  \Carbon\Carbon                                 created_at
21
 * @property  \Carbon\Carbon                                 updated_at
22
 * @property  \Illuminate\Database\Eloquent\Collection       roles
23
 * @property  \Arcanedev\LaravelAuth\Models\PermissionsGroup group
24
 */
25
class Permission extends Model implements PermissionContract
26
{
27
    /* ------------------------------------------------------------------------------------------------
28
     |  Traits
29
     | ------------------------------------------------------------------------------------------------
30
     */
31
    use AuthPermissionRelationships, AuthRoleTrait, Slugable;
32
33
    /* ------------------------------------------------------------------------------------------------
34
     |  Properties
35
     | ------------------------------------------------------------------------------------------------
36
     */
37
    /**
38
     * The attributes that are mass assignable.
39
     *
40
     * @var array
41
     */
42
    protected $fillable = ['group_id', 'name', 'slug', 'description'];
43
44
    /* ------------------------------------------------------------------------------------------------
45
     |  Constructor
46
     | ------------------------------------------------------------------------------------------------
47
     */
48
    /**
49
     * Create a new Eloquent model instance.
50
     *
51
     * @param  array  $attributes
52
     */
53 240
    public function __construct(array $attributes = [])
54
    {
55 240
        $this->setTable(config('laravel-auth.permissions.table', 'permissions'));
56
57 240
        parent::__construct($attributes);
58 240
    }
59
60
    /* ------------------------------------------------------------------------------------------------
61
     |  Relationships
62
     | ------------------------------------------------------------------------------------------------
63
     */
64
    /**
65
     * Permission belongs to one group.
66
     *
67
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
68
     */
69 4
    public function group()
70
    {
71 4
        return $this->belongsTo(PermissionsGroup::class, 'group_id');
72
    }
73
74
    /* ------------------------------------------------------------------------------------------------
75
     |  Setters & Getters
76
     | ------------------------------------------------------------------------------------------------
77
     */
78
    /**
79
     * Set the slug attribute.
80
     *
81
     * @param  string  $slug
82
     */
83 100
    public function setSlugAttribute($slug)
84
    {
85 100
        $this->attributes['slug'] = $this->slugify($slug);
86 100
    }
87
}
88