ProductCategory.php 943 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Model;
  3. use App\Scopes\TopDepartmentScope;
  4. use Illuminate\Database\Eloquent\Model;
  5. class ProductCategory extends Model
  6. {
  7. protected $guarded = [];
  8. protected $table = "product_category"; //指定表
  9. const CREATED_AT = 'crt_time';
  10. const UPDATED_AT = 'upd_time';
  11. protected $dateFormat = 'U';
  12. public static $user = [];
  13. public static $search = [];
  14. public static $is_search = false;
  15. public function __construct(array $attributes = [])
  16. {
  17. if(! empty($attributes['userData'])) {
  18. self::$user = $attributes['userData'];
  19. self::$search = $attributes['search'] ?? [];
  20. self::$is_search = true;
  21. }
  22. parent::__construct($attributes);
  23. }
  24. protected static function boot(){
  25. parent::boot();
  26. if(self::$is_search){
  27. static::addGlobalScope(new TopDepartmentScope(self::$user, self::$search));
  28. }
  29. }
  30. }