Authority.php 886 B

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