Skip to content
关注公众号,获取新课通知

商品类型列表


控制器 app/controller/admin/GoodsType.php

php
public function index()
{
    $param = $this->request->param();
    $limit = intval(getValByKey('limit',$param,10));
    $page = getValByKey('page',$param,1);
    $totalCount = $this->M->count();
    $list = $this->M->page($page,$limit)->order([
        'order'=>'desc',
        'id'=>'desc'
    ])->with(['skus','goodsTypeValues'])->select();
    return showSuccess([
        'list'=>$list,
        'totalCount'=>$totalCount
    ]);
}

模型 app/model/GoodsType.php

php
	// 关联规格值
    public function goodsTypeValues(){
        return $this->hasMany('GoodsTypeValue');
    }

    // 关联skus
    public function skus(){
        return $this->belongsToMany('Skus','SkusGoodsType');
    }

验证器 app/validate/admin/GoodsType.php

php
protected $rule = [
    'page' => 'require|integer|>:0',
];
protected $scene = [
    ...
    'index'=>['page'],
    ...
];

路由 router/admin.php

php
Route::get('goods_type/:page','admin.GoodsType/index');