~~~
<?php
namespace app\api\controller\v1;
use app\api\validate\IDMustBePostiveInt;
use app\api\model\Banner as BannerModel;
use app\lib\exception\BannerMissException;
class Banner{
//获取指定id的banner信息
public function getBanner($id)
{
(new IDMustBePostiveInt())->goCheck();
$banner=BannerModel::with(['items','items.img'])->find($id);
//隐藏字段
//$banner->hidden(['delete_time','update_time']);
//只显示字段
$banner->visible(['id']);
if(!$banner){
throw new BannerMissException();
}
return $banner;
}
}
~~~
![](https://box.kancloud.cn/b01ffe0f06fe47291129aa31ad7a30af_688x736.png)
![](https://box.kancloud.cn/2ad59905bad4d8235973e420df01f885_621x579.png)