| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace app\common\model;
- class Banner extends BaseModel
- {
- /**
- * @var string
- */
- protected $name = 'banner';
- /**
- * @var array
- */
- protected $auto = [];
- /**
- * @var array
- */
- protected $insert = ['created_at','updated_at'];
- /**
- * @var array
- */
- protected $update = ['updated_at'];
- /**
- * @var array
- */
- protected $hidden = ['deleted_at','updated_at'];
- /**
- * 关联获取Banner Item表
- * @return \think\model\relation\HasMany
- */
- public function items()
- {
- return $this->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);
- }
- }
|