hasMany('BannerItem', 'banner_id', 'id')->where(['status' => 1]); } /** * 获取Banner 数据 * @param $id * * @return array|\PDOStatement|string|\think\Model|null * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public static function getBannerById($id) { return self::with(['items'])->find($id); } }