Completed
Push — master ( 58fb5e...df6768 )
by Fèvre
14s
created

Role::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
namespace Xetaravel\Models;
3
4
use Ultraware\Roles\Contracts\RoleHasRelations as RoleHasRelationsContract;
5
use Ultraware\Roles\Traits\RoleHasRelations;
6
use Ultraware\Roles\Traits\Slugable;
7
8
class Role extends Model implements RoleHasRelationsContract
9
{
10
    use Slugable, RoleHasRelations;
11
12
    /**
13
     * The attributes that are mass assignable.
14
     *
15
     * @var array
16
     */
17
    protected $fillable = [
18
        'name',
19
        'slug',
20
        'description',
21
        'css',
22
        'level'
23
    ];
24
25
    /**
26
     * The "booting" method of the model.
27
     *
28
     * @return void
29
     */
30
    protected static function boot()
31
    {
32
        parent::boot();
33
34
        // Generated the slug before updating.
35
        static::updating(function ($model) {
36
            $model->setSlugAttribute($model->name);
37
        });
38
39
        // Generated the slug before creating.
40
        static::creating(function ($model) {
41
            $model->setSlugAttribute($model->name);
42
        });
43
    }
44
}
45