Storehouse.php 888 B

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