Completed
Pull Request — master (#1)
by ARCANEDEV
04:39
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  string                                          name
17
 * @property  string                                          slug
18
 * @property  string                                          description
19
 * @property  \Carbon\Carbon                                  created_at
20
 * @property  \Carbon\Carbon                                  updated_at
21
 * @property  \Illuminate\Database\Eloquent\Collection        roles
22
 * @property  \Arcanedev\LaravelAuth\Models\PermissionsGroup  group
23
 */
24
class Permission extends Model implements PermissionContract
25
{
26
    /* ------------------------------------------------------------------------------------------------
27
     |  Traits
28
     | ------------------------------------------------------------------------------------------------
29
     */
30
    use AuthPermissionRelationships, AuthRoleTrait, Slugable;
31
32
    /* ------------------------------------------------------------------------------------------------
33
     |  Properties
34
     | ------------------------------------------------------------------------------------------------
35
     */
36
    /**
37
     * The attributes that are mass assignable.
38
     *
39
     * @var array
40
     */
41
    protected $fillable = ['group_id', 'name', 'slug', 'description'];
42
43
    /* ------------------------------------------------------------------------------------------------
44
     |  Constructor
45
     | ------------------------------------------------------------------------------------------------
46
     */
47
    /**
48
     * Create a new Eloquent model instance.
49
     *
50
     * @param  array  $attributes
51
     */
52 228
    public function __construct(array $attributes = [])
53
    {
54 228
        $this->setTable(config('laravel-auth.permissions.table', 'permissions'));
55
56 228
        parent::__construct($attributes);
57 228
    }
58
59
    /* ------------------------------------------------------------------------------------------------
60
     |  Relationships
61
     | ------------------------------------------------------------------------------------------------
62
     */
63
    /**
64
     * Permission belongs to one group.
65
     *
66
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
67
     */
68 4
    public function group()
69
    {
70 4
        return $this->belongsTo(PermissionsGroup::class, 'group_id');
71
    }
72
73
    /* ------------------------------------------------------------------------------------------------
74
     |  Setters & Getters
75
     | ------------------------------------------------------------------------------------------------
76
     */
77
    /**
78
     * Set the slug attribute.
79
     *
80
     * @param  string  $slug
81
     */
82 88
    public function setSlugAttribute($slug)
83
    {
84 88
        $this->attributes['slug'] = $this->slugify($slug);
85 88
    }
86
}
87