Role.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Model;
  3. use App\Scopes\DepartmentScope;
  4. use Illuminate\Database\Eloquent\Model;
  5. /**
  6. * 角色管理
  7. * Class Unit
  8. * @package App\Models
  9. */
  10. class Role extends Model
  11. {
  12. protected $guarded = [];
  13. protected $table = "role"; //指定表
  14. const CREATED_AT = 'crt_time';
  15. const UPDATED_AT = 'upd_time';
  16. protected $dateFormat = 'U';
  17. public static $user = [];
  18. public static $search = [];
  19. public static $is_search = false;
  20. const range_function = '';
  21. public function __construct(array $attributes = [])
  22. {
  23. if(! empty($attributes['userData'])) {
  24. self::$user = $attributes['userData'];
  25. self::$user['range_function'] = self::range_function;
  26. self::$search = $attributes['search'] ?? [];
  27. self::$is_search = true;
  28. }
  29. parent::__construct($attributes);
  30. }
  31. protected static function boot(){
  32. parent::boot();
  33. if(self::$is_search){
  34. static::addGlobalScope(new DepartmentScope(self::$user,self::$search));
  35. }
  36. }
  37. }