Ability::path()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Thinkstudeo\Rakshak;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Str;
7
use Thinkstudeo\Rakshak\Traits\UuidAsPrimaryKey;
8
9
class Ability extends Model
10
{
11
    use UuidAsPrimaryKey;
12
13
    /**
14
     * Set the incrementing property to false.
15
     *
16
     * @var bool
17
     */
18
    public $incrementing = false;
19
20
    /**
21
     * The primary key column type.
22
     *
23
     * @var string
24
     */
25
    protected $keyType = 'string';
26
27
    /**
28
     * The fields which are protected against mass assignment.
29
     *
30
     * @var array
31
     */
32
    protected $guarded = ['id'];
33
34
    /**
35
     * Set the slug value from the name attribute.
36
     *
37
     * @param string $value
38
     * @return void
39
     */
40
    public function setNameAttribute($value)
41
    {
42
        $this->attributes['slug'] = Str::slug($value, '-');
43
        $this->attributes['name'] = $value;
44
    }
45
46
    /**
47
     * Path to the ability.
48
     *
49
     * @return string
50
     */
51
    public function path()
52
    {
53
        return '/'.config('rakshak.route_prefix')."/abilities/{$this->{$this->getRouteKeyName()}}";
54
    }
55
56
    /**
57
     * Get all Roles associated with the Ability.
58
     *
59
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
60
     */
61
    public function roles()
62
    {
63
        return $this->belongsToMany(Role::class);
64
    }
65
}
66