Storehouse.php 1017 B

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 Storehouse extends Model
  11. {
  12. // protected $fillable = ['userData'];
  13. protected $guarded = [];
  14. protected $table = "storehouse"; //指定表
  15. const CREATED_AT = 'crt_time';
  16. const UPDATED_AT = 'upd_time';
  17. protected $dateFormat = 'U';
  18. public static $user = [];
  19. public static $search = [];
  20. public static $is_search = false;
  21. public function __construct(array $attributes = [])
  22. {
  23. if(! empty($attributes['userData'])) {
  24. self::$user = $attributes['userData'];
  25. self::$search = $attributes['search'];
  26. self::$is_search = true;
  27. }
  28. parent::__construct($attributes);
  29. }
  30. protected static function boot(){
  31. parent::boot();
  32. if(self::$is_search){
  33. static::addGlobalScope(new DepartmentScope(self::$user, self::$search));
  34. }
  35. }
  36. }