Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
33.33% |
1 / 3 |
CRAP | |
9.09% |
1 / 11 |
| Authority | |
0.00% |
0 / 1 |
|
33.33% |
1 / 3 |
43.81 | |
9.09% |
1 / 11 |
| roles | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| getNameFilteredAttribute | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 6 |
|||
| getOwnerIdAttribute | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 4 |
|||
| <?php | |
| namespace App; | |
| use Illuminate\Database\Eloquent\Model; | |
| class Authority extends Model | |
| { | |
| protected $fillable = ['name','remark','id_parent','alias_name']; | |
| function roles(){ | |
| return $this->belongsToMany('App\Role','authority_role','id_authority','id_role'); | |
| } | |
| function getNameFilteredAttribute(){ | |
| preg_match('#(.*)(_[0-9]*?$)#',$this['name'],$arr); | |
| if($arr){ | |
| $id=str_replace('_','',$arr[2]); | |
| $owner = Owner::find($id); | |
| if($owner){return "{$arr[1]}({$owner['name']})";} | |
| } | |
| return $this['name']; | |
| } | |
| function getOwnerIdAttribute(){ | |
| preg_match('#_([0-9]*?)$#',$this['name'],$arr); | |
| if(count($arr)>1&&$arr[1]){ | |
| return $arr[1]; | |
| } | |
| return ''; | |
| } | |
| } |