Warehouse.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App\Traits\ModelTimeFormat;
  5. use App\Traits\ModelLogChanging;
  6. use Illuminate\Database\Eloquent\Relations\HasMany;
  7. class Warehouse extends Model
  8. {
  9. use ModelLogChanging;
  10. use ModelTimeFormat;
  11. protected $fillable=['name','code',"production_capacity","reduced_production_capacity_coefficient","address","principal","phone","province_id","city_id","county_id"];
  12. public function userWorkgroups(){
  13. return $this->hasMany('App\UserWorkgroup');
  14. }
  15. public function province()
  16. { //省
  17. return $this->belongsTo(Region::class)->where("type",1);
  18. }
  19. public function city()
  20. { //市
  21. return $this->belongsTo(Region::class)->where("type",2);
  22. }
  23. public function county()
  24. { //区县
  25. return $this->belongsTo(Region::class)->where("type",3);
  26. }
  27. /**
  28. * @return HasMany
  29. */
  30. public function laborCompanies(): HasMany
  31. {
  32. return $this->hasMany(LaborCompany::class,'warehouse_id','id');
  33. }
  34. }