Authority.php 939 B

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