| Total Complexity | 5 |
| Total Lines | 76 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 11 | class Role extends AbstractModel |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * The "booting" method of the model. |
||
| 15 | * |
||
| 16 | * @return void |
||
| 17 | */ |
||
| 18 | public static function boot() |
||
| 19 | { |
||
| 20 | parent::boot(); |
||
| 21 | |||
| 22 | // Global scopes |
||
| 23 | static::addGlobalScope(new OrderScope('order', 'asc')); |
||
| 24 | } |
||
| 25 | |||
| 26 | protected $connection = 'mysql'; |
||
| 27 | protected $table = 'role'; |
||
| 28 | protected $primaryKey = 'role_id'; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * The attributes that are mass assignable. |
||
| 32 | * |
||
| 33 | * @var array |
||
| 34 | */ |
||
| 35 | protected $fillable = [ |
||
| 36 | 'role_id', |
||
| 37 | 'type', |
||
| 38 | 'name', |
||
| 39 | 'description', |
||
| 40 | 'class', |
||
| 41 | 'order', |
||
| 42 | ]; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Query Builder. |
||
| 46 | * |
||
| 47 | * @param $query |
||
| 48 | * |
||
| 49 | * @return RoleBuilder |
||
| 50 | */ |
||
| 51 | public function newEloquentBuilder($query) |
||
| 52 | { |
||
| 53 | return new RoleBuilder($query); |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Custom Role query Builder. |
||
| 58 | * |
||
| 59 | * @return RoleBuilder|Builder |
||
| 60 | */ |
||
| 61 | public static function query(): RoleBuilder |
||
| 62 | { |
||
| 63 | return parent::query(); |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * 'users' with roles. |
||
| 68 | * |
||
| 69 | * @return HasMany |
||
| 70 | */ |
||
| 71 | public function users() |
||
| 72 | { |
||
| 73 | return $this->hasMany(User::class, 'role_id', 'role_id') |
||
| 74 | ->where('type', '=', 'user'); |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Retrieve the 'class' attribute with a default value. |
||
| 79 | * |
||
| 80 | * @param null $value |
||
|
|
|||
| 81 | * |
||
| 82 | * @return string |
||
| 83 | */ |
||
| 84 | public function getClassAttribute($value = null): string |
||
| 87 | } |
||
| 88 | } |
||
| 89 |