Authority.php 789 B

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