| Code Coverage
| Classes and Traits | Functions and Methods | Lines
Total | 0.00% covered (danger) | 0.00% | 0 / 1 | 33.33% covered (danger) | 33.33% | 1 / 3 | CRAP | 9.09% covered (danger) | 9.09% | 1 / 11
Authority | 0.00% covered (danger) | 0.00% | 0 / 1 | 33.33% covered (danger) | 33.33% | 1 / 3 | 43.81 | 9.09% covered (danger) | 9.09% | 1 / 11
roles | 100.00% covered (success) | 100.00% | 1 / 1 | 1 | 100.00% covered (success) | 100.00% | 1 / 1
getNameFilteredAttribute | 0.00% covered (danger) | 0.00% | 0 / 1 | 12.00 | 0.00% covered (danger) | 0.00% | 0 / 6
getOwnerIdAttribute | 0.00% covered (danger) | 0.00% | 0 / 1 | 12.00 | 0.00% covered (danger) | 0.00% | 0 / 4

1 | <?php
2 |
3 | namespace App;
4 |
5 | use Illuminate\Database\Eloquent\Model;
6 |
7 | class Authority extends Model
8 | {
9 | protected $fillable = ['name','remark','id_parent','alias_name'];
10 | function roles(){
11 | return $this->belongsToMany('App\Role','authority_role','id_authority','id_role');
12 | }
13 | function getNameFilteredAttribute(){
14 | preg_match('#(.*)(_[0-9]*?$)#',$this['name'],$arr);
15 | if($arr){
16 | $id=str_replace('_','',$arr[2]);
17 | $owner = Owner::find($id);
18 | if($owner){return "{$arr[1]}({$owner['name']})";}
19 | }
20 | return $this['name'];
21 | }
22 | function getOwnerIdAttribute(){
23 | preg_match('#_([0-9]*?)$#',$this['name'],$arr);
24 | if(count($arr)>1&&$arr[1]){
25 | return $arr[1];
26 | }
27 | return '';
28 | }
29 | }