当前表model
1 /* 2 * 关联货品管理类别中间表Model 3 * @auth jackie <2019.10.18> 4 */ 5 public function hasManyGoodsManagementType() 6 { 7 return $this->hasMany(KeyGoodsmanagementType::class,'management_id','id'); 8 } 9 10 /* 11 * @param $management_type_name 货品管理类别 12 * @auth jackie <2019.10.22> 13 */ 14 public function scopeManagementTypeLike($query,$management_type_name) 15 { 16 return $query->whereHas('hasManyGoodsManagementType.hasOneGoodsManagementType',function ($query1) use($management_type_name){ 17 return $query1->where('name','like',$management_type_name); 18 }); 19 }
中间表model
/* * 关联货品管理类别表 * @auth jackie <2019.10.> */ public function hasOneGoodsManagementType() { return $this->hasOne(GoodsManagementType::class,'id','management_type_id'); }